Understanding the physics of teleporting bodies

Hey there,

I am tinkering with teleporting objects while applying forces to them (my use case is recentering the physics scene when the objects are far from the origin so I avoid the 32bit imprecision of Havok calculations)

I think there is a bunch of stuff I don’t really understand as shown in this PG:

Basically, the cube is moving through space and I will teleport it back to the origin when it gets too far.

The issue happens on the frame where the teleportation happens: the object position changes suddenly and I need disablePreStep=false to make sure Havok acknowledges the change.

Using “Option 2”, I then apply my forces (thrust and gravity) on the object at its new position (here, teleported to the origin) but the object starts spinning. This makes me believe havok applies the force far from the object center, hence creating the rotation. I don’t understand why this happen since I updated the position of the object and used disablePreStep=false

What puzzles me even more is the fact “Option 1” does not have the same problem: we apply the force on the outdated object position (not teleported), then we teleport the object (and I expect Havok to work with the teleported position with disablePreStep=false). This should create a sync issue and some angular momentum, but instead everything seems to be working fine.

I am ok with using Option 1 since it works, but I would really like to understand why this is happening at all :thinking:

cc @Cedric

Some elements to understand it:

getObjectCenterWorld returns a copy of the transformNode.position. Without querying Havok physics state.

Physics has to tick to commit the transform node change to Havok.

Force is applied at (0,0,0) and that force command is buffered by Havok.

And there is the if. case 1, position is far away. case 2, position has been set to 0.

I don’t have the full picture in mind but you are right with the position the force is applied to. With that frame delay, it’s not in sync with transform node and a torque is induced.

2 Likes

Thanks for the answer!

So if I understand correctly, applyForce calls will be sent to Havok (through HP_Body_ApplyImpulse) which has the not-yet-teleported transform to update the linear and angular velocities. For those velocity updates to make sense, I need to send the not-yet-teleported point of contact for the force.

Then during the physics tick, the havok transform is updated with the teleportation and applies the previously computed velocities to the body.

I think my confusion stemmed from believing applyForce would simply register the force for application during the physics tick, which in the end is not true since Havok seems to update the velocities right away, which explains why I must use the not-yet-teleported center of the object.

1 Like