- Home /
Question by
FunkiestFak · Dec 12, 2018 at 03:42 AM ·
2drotationmovement
How to move a object the way its facing in 2D
hi, im trying to make my first game, I already got the basic movement of the player from a tutorial online, but I want it to rotate using "A" and "D" and move the way it's facing, how would I do this? this is my script.
public class PlayerController : MonoBehaviour {
public float playerSpeed;
private Rigidbody2D rb2d;
void Start()
{
rb2d = GetComponent<Rigidbody2D>();
}
void FixedUpdate()
{
float moveHorizontal = Input.GetAxis("Horizontal");
float moveVertical = Input.GetAxis("Vertical");
Vector2 movement = new Vector2(moveHorizontal, moveVertical);
rb2d.AddForce(movement * playerSpeed);
}
}
Comment