I am making a game and am having an issue because when the left key is held down the character should go left and when the right key is held down the character should go right. This is all working but the problem is when a key is pressed the character moves slightly in the corresponding direction, waits about half a second until the computer realizes the key is being held down, then the character moves as I want it to. How do I get rid of the delay after the key is held down? Here is my code for moving the character.
$(document).keydown(function(key) {
switch(parseInt(key.which, 10)) {
case 37:
$('#player').animate({left:'-=5px'}, 1);
break;
case 39:
$('#player').animate({left:'+=5px'}, 1);
break;
}
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>