using UnityEngine;
using System.Collections;
public class PlayerMovement : MonoBehaviour {
//public variables
public float acceleration = 5;
public float decceleration = .2f;
public float gravity = 21;
public float airAcceleration = 2.5f;
public float jumpAllowTime = .1f;
public float wallJump = 10;
//Private variables
float curSpeed;
float jumpAllowTrack;
float moveSmooth;
CharacterController cont;
bool run = false;
Vector3 curMove;
//Smoothdamp variables
float walkMoveV;
float runMoveV;
float stopMoveV;
float airAccelerationV;
private Stats Player;
//Get that stats
void Awake (){
Player = GetComponent<Stats>();
}
// Use this for initialization
void Start () {
cont = GetComponent<CharacterController>();
}
// Update is called once per frame
void Update () {
//sprint and movement.
if(Input.GetKey (KeyCode.A) || Input.GetKey (KeyCode.D))
run = true;
else
if(run == true && Input.GetKey (KeyCode.LeftShift))
curSpeed = Mathf.SmoothDamp(curSpeed, Input.GetAxisRaw ("Horizontal") * Player.runSpeed, ref runMoveV, moveSmooth);
else if (run == true)
curSpeed = Mathf.SmoothDamp (curSpeed, Input.GetAxisRaw ("Horizontal") * Player.speed, ref walkMoveV , moveSmooth);
else
curSpeed = Mathf.SmoothDamp (curSpeed, 0, ref stopMoveV , moveSmooth);
if(Input.GetButtonDown ("Jump") && jumpAllowTrack >= 0)
curMove.y = Player.jump;
// the actual movement
cont.Move(curMove*Time.deltaTime);
curMove = new Vector3(curSpeed, curMove.y, 0);
//Is it grounded?
if(cont.isGrounded){
//reset vertical movement
curMove.y=0;
// normal control
moveSmooth = acceleration;
jumpAllowTrack = jumpAllowTime;
}
if(!cont.isGrounded){
// enable the gravity
curMove -= new Vector3(0, gravity * Time.deltaTime, 0);
//give less control in the air
moveSmooth = airAcceleration;
jumpAllowTrack -= Time.deltaTime;
}
}
}
I have this code which has no errors and works just how I want it to, I reset the input manager so that it has all of the default settings, I’ve tried making a new input axis and no matter what the W and A keys do not work and I have to wait a few seconds before the left and right keys start working and i know it is not my keyboard because typing for everything works perfectly fine.