Aaron
Aaron

Reputation: 133

How to add a force to an object in Unity not relative to the objects rotation but relative to the game coordinates?

I am creating a 2d game and would like to have an object move up. I don't want it to move up relative to the object, but up relative to the game coordinates. I am currently using Rigidbody.AddForce(). Does anyone know of a way to do this?

Upvotes: 1

Views: 1733

Answers (2)

Aaron
Aaron

Reputation: 133

figured it out. Instead of doing Rigidbody.AddForce(transform.up);, use Rigidbody.AddForce(new Vector2(x, y));

Upvotes: 1

Dhinesh Vinayak
Dhinesh Vinayak

Reputation: 1

Do You want it to AddForce Relative to Local space or world space?, If you want it to move in local space use AddRelativeForce(..), if you want to move based on world use AddForce(..)

Check Out Doc

Upvotes: 0

Related Questions