Topic was automatically imported from the old Question2Answer platform.
Asked By
BraindeadBZH
Hi everyone,
I’m trying to simulate a vehicle with a thruster in the back, so not centered at (0, 0, 0), but the add_force function drives me nuts. If I look at this sentence, from apply_impulse:
The position uses the rotation of the global coordinate system, but is centered at the object’s origin
I have tried a lot of thing, but I cannot wrap my around on how to make my force vector take into account the rotation of the vehicle.
You get the local axis vectors in global space from transform.basis or global_transform.basis. So a relative position 2 local units back on the z-axis in global space is global_transform.basis.z * -2.0
The thing is when applying a force, you don’t want to apply the translation, just global rotation, as the the force position is already in local coordinate.
BraindeadBZH | 2019-06-09 11:32
Local coordinates don’t help you with apply_force or apply_impulse.
If you don’t want to apply to apply force/impulse to the center (=offset (0,0,0)) then you have to specify the offset vector3 in global coordinate system.
‘centered at the object’s origin’ means that you don’t pass a global coordinate but an offset to the objects origin in global space.
Same is with the direction vector of the force/impulse this has to in global space (like i.e. the velocity vector).
I know, this is why, if you look at my add_force_local function (in the pinned answer), I rotate the force and the offset so they are in global coordinate relative to the body center.