TransformNode position not updating as parent position is changed (Typescript)

Using Typescript, I have a class that extends TransformNode. It’s constructor takes an argument called parent
of type Node, and calls this.setParent(parent) on it.

In my scene, when I instantiate this object, it’s parent property correctly shows the parent object that was passed to it.

But when the parent object is moved via parent.position.x += 1.0, the child’s position (and absolutePosition) is not updated accordingly.

Am I missing something? Should I be updating the parent mesh differently? Was this a bug with 3.3.0 (the version I’m using)?

Thanks for any help.

Solved: In the class that extends TransformNode, I added: this.position = parent.position, and same for rotation and scaling. I didn’t think this would be necessary after setting this.parent = parent, but it solves the problem.

1 Like

This should work. Can you repro on the PG?

Is there a way to use Typescript in the PG? If not, it would just take too long to do, sorry.

1 Like

Thanks Brian, that’s good to know. On a side note, I’m really encouraged to continue with Babylon because of the new forums, and the great “quality of life” things like being able to use Typescript in the Playground.

Here’s the repro:

Press “w” to move the sphere’s position up by 1.0, and check the console. Note how the sphereSO.position doesn’t change.

Edit: I should note that adding this.position = parent.position to the ShaderObject’s constructor after the super.setParent call makes it work.

That’s because sphereSO position is reported in “local” space (relative to it’s parent). whereas the ‘sphere’ object is in world co-ordinates, since it has no parent.
Add this to your PG:
console.log(‘sphereSO abs:’, sphereSO.getAbsolutePosition())

1 Like

Thanks Brian, I’m learning a lot from this.

What purpose does sphereSO.computeWorldMatrix(true) serve there? It seems to work with and without that call.

1 Like

You’re right. You only need that whenever position is in world coordinates. It’s an optimization that it’s not available without calling ComputeWorldMatrix after you update position, but is computed in the render.

edit: So, to have it working as you would expect - you should instead be calling sphere.computeWorldMatrix(). I think otherwise you would be lagging behind.