Absolute Position does not change right away when position is changed

Hey all,

I am running into an odd (I think it’s odd) bug where my absolutePosition is not updated after my position property was updated. It seems to take a frame?

Very basic example below, easy to see how absolutePosition still logs 0 after position was changed. When I use setAbsolutePosition it works but… that defeats the purpose in my case, since I would like to know the absolute position of a child mesh, after I have rotated a parent mesh.

https://playground.babylonjs.com/#8538S5#4

Once again I found the answer right after posting… it seems that I need to use getAbsolutePosition instead.

And for rotation I can use this:

Hey I wanted to add some new discoveries here, since as it turns out the solution I saw before didn’t work either. What I had to do is reset the parent to the objects parent! Sounds insane? Check this out:

https://playground.babylonjs.com/#8538S5#8

The code that did it:

    //This does NOT log the correct absoluteRotation
    console.log(sphere2.absoluteRotationQuaternion);

    sphere2.setParent(sphere2.parent);

    //This DOES log the correct absoluteRotation
    console.log(sphere2.absoluteRotationQuaternion);

https://playground.babylonjs.com/#8538S5#9

Just force compute world matrix, and you should be fine.

2 Likes

Omg yes. Much easier :wink: Thanks a bunch @nogalo!!.