Search code examples
c#unity-game-enginegame-physics

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?


Solution

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