使用 Babylon.js 进行角色移动

use*_*697 5 javascript babylonjs

在我准备上学的游戏演示中,我需要使用 WASD 键和箭头键移动我的角色。我设置了一个函数并设置了一个开关盒来监听任何按键。这是我的代码片段:

//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;
})();
Run Code Online (Sandbox Code Playgroud)

我的问题是我的角色跳得太远以至于他从屏幕上消失了。谁能帮我弄清楚我的计算有什么问题?

Raa*_*n W 4

一些东西 -