I am using Unity2D for a simple car / bike physics game. I want when i press the right or left arrow, the wheel sprite to rotate, so the car is moving.
This is my code:
float move=Input.GetAxis("Horizontal");
if (Input.GetKey(KeyCode.RightArrow))
{
rigidbody2D.velocity = new Vector2(move*10,rigidbody2D.velocity.y);
}
if (Input.GetKey(KeyCode.LeftArrow))
{
rigidbody2D.velocity = new Vector2(move * 10, rigidbody2D.velocity.y);
}
But this is just 'pushing' the wheel, is not rotating, and if the car is in the air you can still move it...I need to rotate the wheel, not push it. Can anyone help?