- Home /
Question by
realisticallyawesome · Jun 22, 2020 at 11:39 PM ·
movementcharactercontrollerlag
Character Controller has Input Lag. How do I Fix it?
Hi! My Character Controller keeps moving in its move direction for half a second or so after I release the movement keys (WSAD). I do not know why. I appreciate any help:)
Lines 25 to 35 is Movement Input; In the "KeyMovementInput" Function.
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class PlayerMovement : MonoBehaviour {
public float moveSpeed;
public float jumpForce;
public float sprintSpeed;
public float crouchHeight;
public float crouchSpeed;
private Vector3 moveDirection;
public float gravityScale;
public CharacterController controller;
void Start()
{
//Controller Component
controller = GetComponent<CharacterController>();
}
void Update()
{
//Player Functions
KeyMovementInput();
}
void KeyMovementInput()
{
//Move Player
float yStore = moveDirection.y;
moveDirection = (transform.forward * Input.GetAxis("Vertical") * moveSpeed) + (transform.right * Input.GetAxis("Horizontal") * moveSpeed);
moveDirection = moveDirection.normalized * moveSpeed;
moveDirection.y = yStore;
//Applying "moveDirection" to player
moveDirection.y = moveDirection.y + (Physics.gravity.y * gravityScale);
controller.Move(moveDirection * Time.deltaTime);
}
}
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220613001551im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Character controller or rigidbody? for skateboard 1 Answer
Jet-Pack Script 1 Answer
Controlling speed of diagonal navmesh movement? 0 Answers
Turning to face movement direction 0 Answers
Animation not working correctly, character is going up 0 Answers