Search Unity

Player Movement WASD is backwards?

Discussion in 'Scripting' started by Steelshot, Sep 29, 2016.

Thread Status:
Not open for further replies.
  1. Steelshot

    Steelshot

    Joined:
    Feb 24, 2015
    Posts:
    102
    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.

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class PlayerMovement : MonoBehaviour {
    5.     //Variables
    6.     public float speed = 6.0F;
    7.     public float jumpSpeed = 8.0F;
    8.     public float gravity = 20.0F;
    9.     private Vector3 moveDirection = Vector3.zero;
    10.    
    11.     void Update() {
    12.         CharacterController controller = GetComponent<CharacterController>();
    13.         // is the controller on the ground?
    14.         if (controller.isGrounded) {
    15.             //Feed moveDirection with input.
    16.             moveDirection = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
    17.             moveDirection = transform.TransformDirection(moveDirection);
    18.             //Multiply it by speed.
    19.             moveDirection *= speed;
    20.             //Jumping
    21.             if (Input.GetButton("Jump"))
    22.                 moveDirection.y = jumpSpeed;
    23.            
    24.         }
    25.         //Applying gravity to the controller
    26.         moveDirection.y -= gravity * Time.deltaTime;
    27.         //Making the character move
    28.         controller.Move(moveDirection * Time.deltaTime);
    29.     }
    30. }
    Any help on trying to reverse it? :D
     
  2. arkon

    arkon

    Joined:
    Jun 27, 2011
    Posts:
    1,122
    your player in the scene has his forward pointing 180 degrees backwards, just rotate the players forward to point forward
     
    odryismael likes this.
  3. Steelshot

    Steelshot

    Joined:
    Feb 24, 2015
    Posts:
    102
    Thanks!
     
Thread Status:
Not open for further replies.