Add Local Force with a Rigidbody2D

Hello,
I was wondering how to add local force to a 2D rigidbody. Normally I would use AddRelativeForce but that does not exist for 2d rigidbodys only normal rigidbodys. Basicly I want this to be local.

gameObject.rigidbody2D.AddForce(Vector2.right*power);

Thanks!

Do you mean you want the force to be applied to the ‘right’ relative to the object? If so just use the objects transform.right vector:

gameObject.rigidbody2D.AddForce(gameObject.transform.right*power);

This should work for 2D as there is built in conversion from Vector3’s to Vector2’s, and you only lose the Z component which isn’t relevant for 2D. Note that I’m still very new to Unity 2D so I’m not 100% sure :slight_smile:

Are you sure the Rigidbody2D.AddRelativeForce doesn’t exist?