2016-04-02 430 views
0

因此,我將我在Blender中製作的場景加載到Babylonjs中,並且它產生了一些有趣的效果。基本上,我試圖將重力等運用到場景中,將玩家移動到適當的位置,並使整個場景點亮並可見,但沒有任何效果。這是腳本:Babylonjs中的場景渲染奇怪

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){ 
     var scene = newScene; 
     var light = new BABYLON.PointLight('light', new BABYLON.Vector3(0,0,10), scene); 
     var player = new BABYLON.FreeCamera('player', new BABYLON.Vector3(1,1,1), scene); 
     scene.activeCamera = player; 
     scene.activeCamera.attachControl(canvas, true); 
     scene.enablePhysics(); 
     scene.setGravity(new BABYLON.Vector3(0, -10, 0)); 
     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; 
     newScene.executeWhenReady(function(){ 
      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(); 
}); 

}

我已經是問題:

  1. 我如何渲染距離更高,這樣我就可以查看 整個場景?
  2. 爲什麼我的場景屬性都不起作用(重力,移動等)?
+0

對於第一個問題,您可以更改攝像頭的'position'財產。 – ConnorsFan

+0

我已經嘗試過了,並沒有改變位置,增加了奇怪 –

+0

你可以嘗試在巴比倫遊樂場(http://www.babylonjs-playground.com/)重現你的問題。如果您保存了測試,其他人可以訪問它並進行調試。你也可以諮詢他們的論壇(http://www.html5gamedevs.com/forum/16-babylonjs/)。 – ConnorsFan

回答

0

player相機應設置爲活動的攝像頭:

var player = new BABYLON.FreeCamera('player', new BABYLON.Vector3(1,1,1), scene); 
scene.activeCamera = player; 
scene.activeCamera.attachControl(canvas, true); 
+0

相機運動現在可以工作,但其餘的屬性仍然不起作用。 –

+0

我不容易測試這些屬性(checkCollisions,applyGravity等)。你說相機運動起作用,鑰匙是否工作? – ConnorsFan

+0

是的,相機是可移動的,但是當我按下移動鍵時,它只能向下移動。場景仍然沒有重力或碰撞。 –