I am in need of a function that mimics a crouch button for my character. The character should only crouch while the down arrow key is being held, not just pressed once. How can I achieve this functionality? Below is my attempted code, which unfortunately does not work as intended. Any help would be greatly appreciated!
document.onkeydown = function (event) {
let key = event.key;
while (key == "ArrowDown") {
character.style.width = 50 + "px";
character.style.height = 30 + "px";
character.style.top = 115 + "px";
}
}