AddForceToPosition (to object relative coordinate system).

Hi

If I add a force using the AddForceToPosition method and that force is off-centre, then it causes both movement and torque to the rigidbody:

	public Vector3 pos=new Vector3(0,0,40);
	public Vector3 forceXYZ=new Vector3(0,0,0);
	
	void FixedUpdate () {

		rigidbody.AddForceAtPosition(forceXYZ, transform.position - pos);
	}

However, my code does not take into account the rotation of the object, so the force is always being applied at 40units from transform centre. After the rigidbody has rotated more say 45 degrees, I don’t even understand what’s going on anymore.

I want to maintain the force’s position WITHIN the object’s local coordinate system. What is the best method to use? (For now, the force direction can stay in world coordinates).

I have a feeling this is going to involve those dreaded quaternions…

You probably need to use transform.localPosition instead of transform.position:

Thanks but that’s not what I want because that’s for child objects so that you get coordinates relative to the parent. in this case there is no parent - just a single object.

That rigidbody has rotated so calculating the new position of the force could be done with sine and cosine on its eulers, but I think I need to use quaternions.

Someone must have done this before - I would imagine this is a common operation? Looking for best practises…