In my game I want to move my character using WASD keys. I have set up a class with a method that updates when the player presses any of the WASD keys to move the character. The problem is that it is not updating the character's movement every frame. Every time I press the W key for instance and let it go the character "teleports". Here is the class I made:
//character speed
var movementSpeed;
//character rotation
var rotationSpeed;
//Handles the player's movement
var PlayerMovement = (function () {
//Constructor
function PlayerMovement() {
this.gameObject = null;
this.movementSpeed = 0;
this.rotationSpeed = 0;
}
PlayerMovement.prototype.onKeyReleased = function (key) {
switch(key)
{
case KeyType.W:
case KeyType.UpArrow:
console.log("Moving up");
this.gameObject.meshObject.position.z += movementSpeed * Tools.getDeltaTime;
break;
}
}
return PlayerMovement;
})();
My question is: what am I doing wrong?