problem with rotation movement

hey, i’m writing some basic 2d movement rotation code and i’m having a problem. in the attached code, something is causing my left movement to always move right. if i disable the rotation code, the movement works correctly and if i disable the movement code, the rotation works correctly. I’m not sure why my values are not working as intended. any insight is appreciated :slight_smile:

private var doublejump = 0;
private var onWall = 0;

var walkSpeed: float = 150.0;
var dashSpeed: float = 10.0;
var dashDistance: float = 5.0;
var runSpeed: float = 300.0;

var jumpSpeed : float = 200.0;
var jumpHeight: float = 16.0;
var maxFallingSpeed: float = 20.0;
var airControlFactor: float = 1.0;

var lookDirection : int;
var faceRight : Vector3 = Vector3(0,0,1);
var faceLeft : Vector3 = Vector3(0,0,-1);
var rotationSmoothing: float = 10.0;
var speedSmoothing: float = 5.0;

var gravity : float = 400.0;

private var moveDirection : Vector3 = Vector3.zero;

function OnTriggerEnter (other : Collider) 
{
    if (other.name == "Wall")
    {
    	onWall = 1;
    }
}

function OnTriggerExit (other : Collider) 
{
    if (other.name == "Wall")
    {
    	onWall = 0;
    }
}

function FixedUpdate () 
{
	transform.position.z = 0;
}

function Update() 
{			
    var controller : CharacterController = GetComponent(CharacterController);
    var horizontalDirection = Input.GetAxisRaw ("Horizontal");
     
    //movement
    if (controller.isGrounded) 
    {
        // We are grounded, so recalculate
        // move direction directly from axes
        doublejump = 0; 
        
        moveDirection = Vector3(horizontalDirection, 0, 0);    
    	moveDirection = transform.TransformDirection(moveDirection) * walkSpeed;
		print(moveDirection);
         //single jump
        if (Input.GetButtonDown ("Jump")) 
        {
            moveDirection.y = jumpSpeed;
            doublejump = 1;
            print("singlejump");
        }
    }
    
    //double jump
   	if (onWall == 0  controller.isGrounded == false)
   	{ 		
    	if (Input.GetButtonDown ("Jump")  doublejump == 1) 
		{
		   	moveDirection.x = Input.GetAxis("Horizontal") * walkSpeed;
		   	moveDirection.y = jumpSpeed;
		   	doublejump = 0;
		   	print("doublejump");
		}
    }
   
   	//wall jump
   	if (onWall == 1  controller.isGrounded == false)
   	{
   		print("touching the wall in air");
   	}
   	
	switch (horizontalDirection)
	{
		case 1:
			lookDirection = 1;
			break;
		case -1:
			lookDirection = 2;
			break;
		default:
			break;
	}
	
	switch (lookDirection)
	{
		case 2:
			transform.rotation = Quaternion.Slerp ( transform.rotation, Quaternion.LookRotation (faceLeft), Time.deltaTime * rotationSmoothing);
			break;
		case 1:
			transform.rotation = Quaternion.Slerp ( transform.rotation, Quaternion.LookRotation (faceRight), Time.deltaTime * rotationSmoothing);
			break;
		default:
			break;
	}
    
    // Apply gravity
    moveDirection.y -= gravity * Time.deltaTime;
    
    // Move the controller
    controller.Move(moveDirection * Time.deltaTime);
}

well hmm. I can’t see anything wrong that stand out, but maybe when you use the Input.GetAxix(“Horizontal”) it isn’t changing the direction correctly. Since that method gives input from -1 to 1 such as when you hit the a key its -1 and d key it is 1 maybe at some point it is changing both directions to positive or negative so you can’t actually change you direction.

Also check the transform on you player model to see what direction is which relative to him. Cuz his fron might be pointing in a direction you may think his back or side is facing.

found the problem. it was this line
moveDirection = transform.TransformDirection(moveDirection) * walkSpeed;
the TransformDirection was screwin it up. i removed it and i’m all good now