Hi everyone,

I'm trying to simulate a vehicle with a thruster in the back, so not centered at (0, 0, 0), but the addforce function drives me nuts. If I look at this sentence, from applyimpulse:

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.

If someone can help? Thanks

in Engine

Here what I came up with, where self is a RigidBody:

``````func add_force_local(force: Vector3, pos: Vector3):
pos_local = self.transform.basis.xform(pos)
force_local = self.transform.basis.xform(force)
``````
by (1,032 points)
edited

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`

by (3,216 points)

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.

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 put something up for reading for this topic:
https://godotforums.org/discussion/18480/godot-3d-vector-physics-cheat-sheet

I know, this is why, if you look at my addforcelocal function (in the pinned answer), I rotate the force and the offset so they are in global coordinate relative to the body center.

Thanks for the link, I'll bookmark that.