- Home /
Question by
mavmak · Mar 22, 2014 at 08:51 AM ·
rigidbody2ddirection
Move a rigidbody to its facing direction
I have a rigidbody2D which is rotating when the user press the left arrow, I want when the user press the up arrow to move that object to each facing direction. Any help?
if (Input.GetKey(KeyCode.LeftArrow))
{
rigidbody2D.AddTorque(Input.GetAxis("Horizontal"));
}
else
{
rigidbody2D.angularVelocity = 0;
}
move.png
(329.0 kB)
Comment
Answer by whydoidoit · Mar 22, 2014 at 08:52 AM
You should do:
rigidbody2D.AddForce(transform.up * powerOfTheForce);