How to request local plane velocity of 2d object

Hi,

On unity about 12 hours now. I am hoping to obtain the velocity of a game object relative to its rotation / 2D facing angle (not relative to world X/Y/Z).

This is to say if +Y indicated a positive vertical velocity and +X indicated a positive horizontal velocity then an object with velocity +Y would have Velocity +X when rotated -90 degrees around Z.

Currently I am using:
For Y velocity ‘transform.GetComponent().velocity[1];’
For X velocity ‘transform.GetComponent().velocity[0];’

However this returns velocity relative to global plane. As i rotate my object I want to see the velocity change.

Appreciate the assistance

Pass the Rigidbody2D.velocity (which is just a vector) to Rigidbody2D.GetVector which will convert it to a local-space vector based upon its rotation.

Rigidbody2D.GetRelvativeVector
will do the opposite and convert a local-space vector to world-space.

1 Like

Edit

Worked. Thanks, excellent method.

1 Like