How do I make a 2D object move in the direction it's facing, like .forward for 3D?

I hope I asked it correctly. Basically, I have a player ship, and I want it to move “forward”, by pressing Up on the Keyboard, with left and right being for rotation.

for Unity2D objects, use

transform.right

rather than

transform.forward

A 2D object moves on the XY plane. For a 2D object, transform.forward will be into the screen and therefore not have any meaning to a rigidbody2D.AddForce() call.

Depending on how you have your app setup, you will likely need either transform.up or transform.right or perhaps -transform.right in your AddForce() call.

Note that if you are using Translate , that anyway uses local space (by default) - so it is automatic.

the easy way is to do transform.up
instead of transform.forward its worked for me
102952-screenshot-2.png

I know this post is really old, but that has not worked for me.

In your demo when you hit right you are rotating on the Z axis clockwise in a negative direction which to my understanding means that your camera is facing forward in the Z axis. You’re going to have to use

if(Input.GetKey("up"))
{
   rigidbody2d.AddForce(transform.up * boostSpeed * 10);
}