How do I set a projectiles velocity based on its rotation? (2D)

Right now in my game, the gun batteries on a ship are either aimed 90 degrees right of the ship or 90 degrees left of the ship, (port and starboard)

I instantiate a projectile (which is aimed upwards) and set its rotation

Rigidbody2D projectileBody = clone.GetComponent<Rigidbody2D> ();
projectileBody.rotation = (m_Rigidbody2D.rotation + 90)%360;

Is there any way that I can calculate a direction & velocity for the projectileBody based only on it’s rotation?

Once your object is rotated, transform.forward will return the forward vector which you can use as the direction of your projectile. Since you’re in 2D, use transform.right instead. Then use direction to calculate the velocity.
For example:

Vector3 direction = projectileBody.transform.right;
Vector3 velocity = direction * 100f * Time.deltaTime;
1 Like