我在Blender做了一个场景,现在我的玩家不会移动。加载场景时没有问题,但是当我尝试使用方向键移动时,它不会起作用。这是代码:
var BABYLON;
var canvas = document.getElementById('gamecanvas');
var engine = new BABYLON.Engine(canvas, true);
var player_height = 2;
var player_speed = 1;
var player_inertia = 0.9;
function INIT_GAME(){
BABYLON.SceneLoader.Load('Scenes/', 'zombie_map.babylon', engine, function(newScene){
newScene.executeWhenReady(function(){
newScene.enablePhysics();
newScene.setGravity(new BABYLON.Vector3(0, -10, 0));
var light = new BABYLON.PointLight('light', new BABYLON.Vector3(0,0,10), newScene);
var player = new BABYLON.FreeCamera('player', new BABYLON.Vector3(1,1,1), newScene);
player.attachControl(canvas, true);
player.ellipsoid = new BABYLON.Vector3(1, player_height, 1);
player.checkCollisions = true;
player.applyGravity = true;
player.keysUp = [87];
player.keysDown = [83];
player.keysLeft = [65];
player.keysRight = [68];
player.inertia = player_inertia;
player.speed = player_speed;
engine.runRenderLoop(function(){
newScene.render();
});
});
});
canvas.height = window.innerHeight;
canvas.width = window.innerWidth;
canvas.requestPointerLock = canvas.requestPointerLock || canvas.mozRequestPointerLock;
canvas.requestPointerLock();
window.addEventListener('resize', function(){
engine.resize();
});
}
如果你能理解为什么我不能动,请告诉我。谢谢!
答案 0 :(得分:0)
您的player
相机应设置为有效相机:
var player = new BABYLON.FreeCamera('player', new BABYLON.Vector3(1,1,1), scene);
scene.activeCamera = player;
scene.activeCamera.attachControl(canvas, true);