I'm making a 2.5D plataform game and I can't get the rotation of the player right. I just want it to rotate on the X-axis while the player move towards left and right. My movement script is this:
if (isWalking)
{
transform.Rotate(0, facingDir, 0);
isWalking = false;
}
else { }
if (Input.GetKey(KeyCode.Space))
GetComponent<Rigidbody>().velocity = new Vector2(GetComponent<Rigidbody>().velocity.x, jumpHeight);
if (Input.GetKey(KeyCode.A)){
GetComponent<Rigidbody>().velocity = new Vector2(-speedHeight, GetComponent<Rigidbody>().velocity.y);
facingDir = 180;
isWalking = true;
}
if (Input.GetKey(KeyCode.D))
{
GetComponent<Rigidbody>().velocity = new Vector2(speedHeight, GetComponent<Rigidbody>().velocity.y);
facingDir = 0 ;
isWalking = true;
}
The best way I could rotate it was by transform.rotate(0,180,0) and (0,0,0), but then it keeps rotating non stop, how can I tell what direction the player is moving on the X-axis so I can transform.rotate properly?