FPS Controller Question Again !!

Hey Guys,

I am having some problems with my script basically if i press A the plater will move to the left. But if i press D he will still move to the right why is that?

here is my script:

42
42

public var MoveSpeed: float = 15;

public var MoveLSpeed : float = 5;

function Update () {
if (Mathf.Abs(Input.GetAxis("Vertical")) > 0){
     var MoveFWD : float =  Input.GetAxis("Vertical")* Time.deltaTime * MoveSpeed ;
     
     transform.Translate(Vector3.forward * MoveFWD);
}

if (Mathf.Abs(Input.GetAxis("Horizontal")) > 0){

     var MoveLeft : float = Input.GetAxis("Horizontal")* Time.deltaTime * MoveLSpeed;
     transform.Translate(Vector3.left * MoveLSpeed);

}
}

	@script RequireComponent (CharacterController)42

42

I would be really thank full if someone can help me :slight_smile:

You’re making the same mistake as before; you should use MoveLeft instead of MoveLSpeed:

  transform.Translate(Vector3.left * MoveLeft);

EDITED: If you’re using a Character Controller, you should move the character using Move. There’s a good and simple example in CharacterController.Move - it moves the character, respect collisions, uses gravity and can even jump! Here’s a copy of this script:

var speed : float = 6.0;
var jumpSpeed : float = 8.0;
var gravity : float = 20.0;

private var moveDirection : Vector3 = Vector3.zero;

function Update() {
    var controller : CharacterController = GetComponent(CharacterController);
    if (controller.isGrounded) {
        // We are grounded, so recalculate
        // move direction directly from axes
        moveDirection = Vector3(Input.GetAxis("Horizontal"), 0,
                                Input.GetAxis("Vertical"));
        moveDirection = transform.TransformDirection(moveDirection);
        moveDirection *= speed;
        
        if (Input.GetButton ("Jump")) {
            moveDirection.y = jumpSpeed;
        }
    }

    // Apply gravity
    moveDirection.y -= gravity * Time.deltaTime;
    
    // Move the controller
    controller.Move(moveDirection * Time.deltaTime);
}