Keyboard delay after build on windows

Hi everyone,

I have a question about an issue I came across regarding keyboard delay after game build.

I’m currently working on a 2D game in which the character can move from side to side and jump. While previewing the game in the unity game screen everything works fine as I move and jump.However, after building and running the game on my computer, the player moves with a slight yet noticeable delay after each key press(side to side movement/jump).

Here’s the code I’m using for the jump and horizontal movement :

//movement code running in FixedUpdate function
_moveInput = Input.GetAxis("Horizontal");
_playerRB.velocity = new Vector2(_moveInput * _speed, _playerRB.velocity.y);

//jump code running in Update function
_playerRB.velocity = Vector2.up * jumpForce;

It’d be great to hear if anyone has any ideas for why this is happening and how it can be fixed.

Thanks!

don’t use FixedUpdate with input. Maybe you should use Input.GetAxisRaw. You shouldn’t split rb.velocity between update and fixed update.

float _moveInput;
Vector2 move;
bool canJump;

void Update () {
_moveInput = Input.GetAxis("Horizontal");
//here your jump button and canJump = true;
}

void FixedUpdate () {
move.x = _moveInput * _speed;

if (canJump) {
move.y = Vector2.up * jumpForce;
canJump = false;
}
else
{
move.y = _playerRB.velocity.y;
}

_playerRB.velocity = move;
}
1 Like