Physics seems to be ignoring worldPosition

I’m trying to make a moving platform that uses rigid body physics, because I want the linear velocity to effect the player.
Here’s the simple code to set its worldPosition

from bge import logic

def moving(cont):
    own = cont.owner
    if not "init" in own:
        own["fixedZ"] = own.worldPosition.z
        own["init"] = True

    own.worldPosition.z = own["fixedZ"]

own.worldPosition.z remains 0, as does own[“fixedZ”], yet it still moves a bit…?

I can just use lock Translation, however I would like to know why this doesn’t work.

This is because physics and physics reaction will be calculated and applied after logic.
I can’t give you a good advice as I never had this situation. (I could solve similar situations, by having one visible and one physics object. This way the delay was not visible).

Hint: you do not need “init”. You can check “fixedZ” directly. If it is not there just set it with an default value.
You can even do this.

own.worldPosition.z = own.get("fixedZ", own.worldPosition.z) 

That explains a lot. Is there a way to toggle lock translation using Python? Like can I change to false or something?

That’s pretty nifty. Thanks :slight_smile: