2017-05-21 130 views
0

代码在VR眼睛中工作得很好,只是第一人移动不起作用。我怎么能卖掉这个问题?为什么FirstpersonVrControls不起作用?

controls = new THREE.VRControls(camera); 
var fpVrControls = new THREE.FirstPersonVRControls(camera, scene); 

fpVrControls.verticalMovement = true; 
... 



function animate(timestamp) { 

    vrControls.update(); //when I paste this line scene doesn't work 
    fpVrControls.update(timestamp); //when I paste this line scene doesn't work 

    effect.requestAnimationFrame(animate); 
    render(); 

} 

回答

0
vrControls.update(); 

vrControlsundefined至少在此范围内。您在此行中使用controlscontrols = new THREE.VRControls(camera);,而不是vrControls

所以除非你在你的代码的其他地方定义了vrControls,否则它会抛出一个错误,说update() is not a function of undefined

此外,我看不到你的HTML,因为你没有包含它,但THREE.VRcontrols不在核心three.js或three.min.js中,所以你需要手动包含它。它在threejs主包\examples\js\controls

编辑

下,请务必检查控制台。它没有被定义,因为它没有加载。 enter image description here

+0

感谢您的快速回答。 我将其替换,但代码不起作用。 我应该使用 - manager.render(scene,camera,timestamp); - 如果是的话,我该如何设置它? – alaprajz

+0

https://jsfiddle.net/alaprajz/cqdyu4gf/ – alaprajz

+0

检查编辑。你不能使用你没有加载的东西。 – OtterFamily