rigidbody2D.AddRelativeForce

Hi guys,

Miss AddRelativeForce for rigidbody2D.

Any idea of how to emulate it?

Thanks!

1 Answer

1

You could transform the force direction into local direction with:

Vector3 relativeForce = transform.InverseTransformDirection(forceDirection);
rigidbody2d.AddForce(new Vector2(relativeForce.x, relativeForce.y));

Thanks :)

No problem. =) If it works for you then please mark it as answered so your question gets removed from the unanswered section.

It's working! But torque is inverted. I have added '-1 to x in new the vector. Vector3 relativeForce = transform.InverseTransformDirection(Vector3.up); rigidbody2D.AddForce(new Vector2(relativeForce.x * -1, relativeForce.y)) GameVortex, can't vote up. Don't have enough karma :'(