How to add force in up direction of a 2d object after it has rotated? I am using AddForce(transform.up) but it always moves the object upwards, irrespective of its rotation. I want to move a ship always in its forward direction even after it spins.
[Edit to include actual solution]
When using a Rigidbody
you are agreeing to no longer modify the transform
directly, and let it be controlled only by the rigidbody
. By rotating using the transform you are not properly allowing the body to have angulart momentum, and can run into a host of differnet issues.
Instead, rotate your object through Rigidbody.MoveRotation()
, or better: Rigidbody.AddTorque()
it's likely you're not actually rotating the transform and are instead rotating the sprite or a child of the transform. You can verify this by using:
You can also try adding the force relative, this should give you the correct direction:
rb.AddRelativeForce(Vector3.Up);
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments