【发布时间】:2017-09-16 03:49:27
【问题描述】:
我在我的 aframe 应用程序中使用物理引擎,并且我希望相机在用户单击按钮时移动。
我想保留物理引擎属性,所以我使用 applyImpulse 作为运动方法。
这是我的示例场景:
<script src="https://aframe.io/releases/0.3.0/aframe.min.js"></script>
<script src="//cdn.rawgit.com/donmccurdy/aframe-extras/v2.3.0/dist/aframe-extras.min.js"></script>
<a-scene physics>
<!-- Camera -->
<a-entity id="cameraWrapper" geometry="box" dynamic-body="mass:1" position="0 1 0" width="2" height="1" depth="2" listener>
<a-entity id="camera" camera universal-controls position="0 1 0" rotation="0 0 0">
</a-entity>
</a-entity>
<a-grid static-body position="0 0 0"></a-grid>
</a-scene>
<div>
<a id="impulseButton">Move</a>
</div>
应该移动相机的 javascript 方法如下所示:
$(document).ready(function(){
$("#impulseButton").on("click",function(){
applyImpulse();
});
function applyImpulse(){
var x = 0;
var y = 0;
var z = 1;
var el = $('#cameraWrapper')[0];
el.body.applyImpulse(
new CANNON.Vec3(x,y,z),
new CANNON.Vec3().copy(el.body.position)
);
}
});
但是,移动似乎不是很流畅,当用户使用 WASD 控件时,cameraWrapper 实体仍保留在旧位置。如何使用 applyImpulse 平滑移动相机?
【问题讨论】:
标签: javascript aframe webvr cannon.js