My C# gave me inverted controls for left and right WASD movement?

Okay so I followed this tutorial after deciding to have a go at making my own C# script for character movement: Jump And Gravity - Game Mechanics - Unity 3D - YouTube

Which gave me an error(which is fixed now) and I ended up with this code:

using UnityEngine;

using System.Collections;

public class KalusBeta : MonoBehaviour
{
private CharacterController controller;

private float verticalVelocity;
private float gravity = 14.0f;
private float jumpForce = 10.0f;

private void Start()
{
	controller = GetComponent<CharacterController>();
}

private void Update()
{
	if (controller.isGrounded) 
	{
		verticalVelocity = -gravity * Time.deltaTime;
		if (Input.GetKeyDown (KeyCode.Space)) 
		{
			verticalVelocity = jumpForce;
		}
	}  
	else 
	{
		verticalVelocity -= gravity * Time.deltaTime;
	}	

	Vector3 moveVector = Vector3.zero;
	moveVector.x = Input.GetAxis("Vertical") * 5.0f;
	moveVector.y = verticalVelocity;
	moveVector.z = Input.GetAxis("Horizontal") * 5.0f;
	controller.Move (moveVector * Time.deltaTime);
}

}

The previous script had Vertical for the moveVector.z axis and Horizontal for the moveVector.x axis. I had to switch the Vertical and Horizontal because pressing W or S made the player move left or right instead of forward or backwards while pressing A or D resulted in the player moving backwards or forwards.

The problem I’m having now is when I press A the player goes right instead of left and D makes the player go left instead of right. I don’t know why this has been inverted or how to fix it, so I would seriously appreciate some help to point out where I’ve gone wrong and how I can fix it.

Below is a quick example of what is happening:

Again, any and all advice would be greatly appreciated :slight_smile:

moveVector.x = Input.GetAxis(“Vertical”) * -5.0f;

Try this one. I havent tested the code myself but if it does what you say, inverting the float value might have a positive effect.