Hi guys!
Sorry if this has been answered elsewhere but I couldn’t find anything. Basically my issue is that the Character Controller seems to stop working after the joystick is released. Not instantly, but rather a quarter second after the fact.
This doesn’t appear to happen if I don’t apply the speed variable to the movement direction variable. Acceleration works fine, but deceleration just seems to get cut off before being finished, and instead of smoothly slowing down to a speed of 0, the character starts slowing down for a quarter second before coming to a total stop.
Movement Code
void ApplyMovement(){
Vector3 MovementDir = new Vector3();
Vector3 camForward = Camera.main.transform.TransformDirection(Vector3.forward);
camForward.y = 0;
camForward = camForward.normalized;
Vector3 camRight = new Vector3(camForward.z, 0, -camForward.x);
float moveHorizontal = Input.GetAxis ("Horizontal");
float moveVertical = Input.GetAxis ("Vertical");
MovementDir = (moveHorizontal * camRight + moveVertical * camForward).normalized ;
SetSpeed ();
MovementDir *= Speed;
comCharacterController.Move (MovementDir);
Debug.Log(comCharacterController.velocity);
}
Speed Code
void SetSpeed(){
if (Input.GetAxis ("Vertical") != 0f || Input.GetAxis ("Horizontal") != 0f) {
if(Speed < SpeedMax || Speed > -SpeedMax){
Speed = Mathf.Lerp(Speed, SpeedMax, Acceleration * Time.deltaTime);
Mathf.Clamp(Speed, -SpeedMax, SpeedMax);
}
} else if (Input.GetAxis ("Vertical") == 0f && Input.GetAxis ("Horizontal") == 0f) {
Speed = Mathf.Lerp(Speed, 0f, Deceleration* Time.deltaTime);
}
}