EulerAngles

Hey, making a 2d sidescroller game

I am on movement, I am getting it to where the player can rotate, but the thing is, if i include the script to rotate the character, the Horizontal input will always be positive no matter if I choose the negative input (aka “left” or “a”). So it will always move right.

Movement:

var controller : CharacterController = GetComponent(CharacterController);
if (controller.isGrounded) 
{
moveDirection = Vector3(Input.GetAxis("Horizontal"), 0,0);
moveDirection = transform.TransformDirection(moveDirection);
moveDirection *= speed;
}

Turning:

if (Input.GetButton("Left"))
{
transform.eulerAngles = Vector3(0,180,0);
}

if (Input.GetButton("Right"))
{
transform.eulerAngles = Vector3(0,0,0);
}

Any help would be awesome.

Not sure if it helps, but have you tried with transform.Rotate(0, 180, 0); instead ? Euler angles flips …

its because of the moveDirection = transform.TransformDirection(moveDirection) makes your transform a localcoordinate transform instead of a worldcoordinate

@ Tiles, that didn’t work, but thanks for your time.

@ scratch that worked, thanks alot.