In a game demo I am putting up for school I need to move my character using the W-A-S-D keys and also the arrow keys. I put up a function and set up a switch case to listen for any of the key presses. Here is my code snippet:
//Handles the player's movement
var PlayerMovement = (function () {
//Constructor
function PlayerMovement() {
this.gameObject = null;
this.movementSpeed = 0;
this.rotationSpeed = 0;
}
PlayerMovement.prototype.awake = function () {
console.log("Awake");
};
PlayerMovement.prototype.update = function () {
//console.log(Tools.getFps());
}
PlayerMovement.prototype.onKeyPressed = function (key) {
switch(key)
{
case KeyType.W:
case KeyType.UpArrow:
console.log("Moving up");
this.gameObject.meshObject.position.z += (BABYLON.Vector3.Up() * this.movementSpeed * Tools.getDeltaTime());
break;
case KeyType.A:
case KeyType.LeftArrow:
//TODO: Do stuff
break;
case KeyType.S:
case KeyType.DownArrow:
//TODO: Do stuff
break;
case KeyType.D:
case KeyType.RightArrow:
//TODO: Do stuff
break;
}
}
return PlayerMovement;
})();
My issue is that my character jumps so far ahead that he vanishes from the screen. Can anyone help me figure out what is wrong with my calculation?