Jump to content

[SOLVED] setVelocityTransform


Recommended Posts

I need to apply rotation to an object over time, and that object has a bunch of children. Each object is a dynamic mesh with a cube body. The rotation is being calculated in update with a smoothstep function so I have the correct rotation for the object at any given time. The question is how should I actually go about applying the rotation?

 

I can do this with setWorldTransform on the parent node without any problems, and that appears to work fine. However, from what I've read I think I should be using setVelocityTransform instead for this kind of controlled movement so that the physics engine tweens the frames in between. Problem is that when I use setVelocityTransform, only the parent object rotates and all the children remain stationary. Checking in the editor after the rotation has happened, the rotation on the child nodes has changed, even though they never appeared to rotate.

 

Visually I can't see any difference between using these two functions, so does it matter which one I use? But in either case, I'd still like to understand why the children don't move as I'd expect them to when using setVelocityTransform.

Link to comment
  • 2 weeks later...

First of all, Node::setWorldTransform() is intended for moving non-physical nodes. Physical objects with bodies should be moved via one of the following:

Secondly, the result depends on whether child nodes have bodies assigned or not. Non-physical children can be moved together with the parent without any restraint. When it comes to physics, you cannot expect that children will follow the parent, as they are driven by physics as well (i.e. rotation set manually to the rendered node is ignored). If you want to move them together, you have to connect them in terms of physics - via a joint. For example, JointFixed.

 

So, what you need to do is connect children with a joint and set setVelocityTransform() if you want a parent (with its children) to jump to a new position. Linear and angular velocities of the parent will change as if it moved all the way through this distance.

setWorldTransform() disregards physical simulation, if any, and simply sets new transformation to a node, its body and children - that is why you see them rotating together.

Link to comment
×
×
  • Create New...