Player Movement WASD is backwards?

Hi there,

I sneaked this bit of code from the unity reference guide
but I noticed a problem when running my game, the character
goes forward when pressing D and backwards when pressing S.
Same thing with the A and D keys.

using UnityEngine;
using System.Collections;

public class PlayerMovement : MonoBehaviour {
    //Variables
    public float speed = 6.0F;
    public float jumpSpeed = 8.0F;
    public float gravity = 20.0F;
    private Vector3 moveDirection = Vector3.zero;
   
    void Update() {
        CharacterController controller = GetComponent<CharacterController>();
        // is the controller on the ground?
        if (controller.isGrounded) {
            //Feed moveDirection with input.
            moveDirection = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
            moveDirection = transform.TransformDirection(moveDirection);
            //Multiply it by speed.
            moveDirection *= speed;
            //Jumping
            if (Input.GetButton("Jump"))
                moveDirection.y = jumpSpeed;
           
        }
        //Applying gravity to the controller
        moveDirection.y -= gravity * Time.deltaTime;
        //Making the character move
        controller.Move(moveDirection * Time.deltaTime);
    }
}

Any help on trying to reverse it? :smile:

your player in the scene has his forward pointing 180 degrees backwards, just rotate the players forward to point forward

1 Like

Thanks!