I have a script that is attached to player it makes an empty follow to position of the character but when I run the game the empty is always deviating from the objects current position how do I fix that?

This is the script:

import bge
import mathutils

cont = bge.logic.getCurrentController()
soul = cont.owner

def main():

    scene = bge.logic.getCurrentScene()
    body = scene.objects['Player']
    sens = cont.sensors['always']
    bodRot = body.worldOrientation.to_euler().z
    solRotList = [soul.worldOrientation.to_euler().x, soul.worldOrientation.to_euler().y, bodRot]
    solRot = mathutils.Euler(solRotList).to_matrix()

    if sens.positive:
        soul.worldPosition = body.worldPosition
        soul.worldOrientation = solRot



It works, but 'soul' takes time to follow the body (hence the 'delay' or 'lag'). The script is attached to an always sensor with True level triggering. I believe the lag is due to less frequency per frame of the script. How do I increase it?

  • 1
    $\begingroup$ Can you clarity your question by providing things such as: the blend file, the script, more details on what you mean by 'lagging' (is it framerate drop?) $\endgroup$
    – sdfgeoff
    Jun 12, 2016 at 20:16
  • $\begingroup$ I mean the deviation between the position of two objects (by the script 'own.worlPosition = obj.worldPosition') which should not be there according to the script, but there is a delay visible for the 'own' to follow the 'obj'. $\endgroup$
    – TheIronLad
    Jun 16, 2016 at 22:30
  • $\begingroup$ You can try using modules instead of scripts $\endgroup$ Jun 19, 2016 at 19:02
  • $\begingroup$ Well using the module mode didn't help. It's the same! $\endgroup$
    – TheIronLad
    Jun 20, 2016 at 21:09

2 Answers 2


That is impossible.

Process flow


You copy the position of the "master" object to a "slave" object. At that moment the positions matches.

Then the logic is done and the physics gets calculated.


It calculates a new position of the master object ... which is now different to the slave as this is not considered by the physics (otherwise your slave object or the master object or both would fly away as they occupy the same space).


Due to the different positional changes (one from logic one from physics) both objects are rendered at two different positions (unless the master was not moving at all).

This is pretty good to see when you do that with cameras (Sky background scene), or objects that occupy nearly the same space (aura). You always get a noticeable one frame delay.


Hide the master object. Use two visible slaves. This way you still have the delay, but it is not visible anymore.

  • $\begingroup$ what if master is the player and it must not be hidden? $\endgroup$
    – TheIronLad
    Jun 16, 2016 at 22:28
  • $\begingroup$ what if master is the player and it must not be hidden? The 'slave' object has no collision on it and the player is a character object. My script is attached to an always sensor with True level triggering. I believe the delay is due to less frequent running of the script. How should I increase its frequency? $\endgroup$
    – TheIronLad
    Jun 19, 2016 at 14:49
  • $\begingroup$ The player has a slave and a master too. The same rules belong to it -> master hidden, slave visible (at least two objects!). $\endgroup$
    – Monster
    Jun 19, 2016 at 15:38
  • $\begingroup$ What? I'm not getting what you're trying to tell. Please elaborate. $\endgroup$
    – TheIronLad
    Jun 20, 2016 at 15:51
  • $\begingroup$ The player (master) object is invisible, but you can move it around. The player (slave) object is visible and follows the master => you get the visual feedback you want. The empty you want to follow -> is a player slave too -> it follows the exact same way the other slave is following. This means there is no delay. [Do not let the empty follow the slave, it should follow the master] $\endgroup$
    – Monster
    Jun 24, 2016 at 5:41

If you're trying to join two objects, have you considered parenting them? If you don't want to copy rotation, vertex parenting?

Normal parenting can be modified at run-time as well.

Another possible solution is to stick the code moving the objects into a pre-draw callback. This way the code is executed just before the frame is drawn. However the game state in the pre-draw callback is a little weird. There is no bge.logic.getCurrentScene() or bge.logic.getCurrentController(), so you have to store nearly everything somewhere in your python module to be able to access it.

  • $\begingroup$ what i want is to slave obj follow the master obj (copy location) but copy the rotation only of z-axis and not the others. I've achieved it but the slave object takes some time (hence the 'delay' or 'lag') to keep up with the master object. How can I remove that lag? $\endgroup$
    – TheIronLad
    Jun 19, 2016 at 14:52

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .