小编use*_*697的帖子

使用 Babylon.js 进行角色移动

在我准备上学的游戏演示中,我需要使用 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: …
Run Code Online (Sandbox Code Playgroud)

javascript babylonjs

5
推荐指数
1
解决办法
3153
查看次数

标签 统计

babylonjs ×1

javascript ×1