【发布时间】:2018-09-26 23:40:04
【问题描述】:
我正在尝试设置一个简单的 a-frame 物理演示,该演示会在点击时重播。遵循 aframe 物理系统和橙色射手演示的基本示例,我将事情简化为下面的代码,除了 rotation.set 动作之外似乎工作正常。该块可以很好地重置位置、速度和 angularVelocity,但不会像它应该的那样更新旋转。浏览器控制台消息是 Uncaught TypeError: Cannot read property 'set' of undefined
在此脚本中设置旋转的最简单方法是什么?
<html>
<head>
<script src="https://aframe.io/releases/0.8.2/aframe.min.js"></script>
<script src="https://unpkg.com/aframe-physics-system@1.4.0/dist/aframe-physics-system.min.js"></script>
</head>
<body>
<a-scene physics background="color: #ccddff">
<a-box id="dropped" position="-1 4 -3" rotation="40 45 0" color="#5577D9" dynamic-body></a-box>
<a-plane position="0 0 -4" rotation="-90 0 0" width="4" height="4" color="brown" static-body></a-plane>
</a-scene>
</body>
<script>
window.addEventListener('click', function () {
// METHOD2 - MOVE THE EXISTING ORANGE
document.querySelector("#dropped").body.position.set(-1, 4, -3);
document.querySelector("#dropped").body.velocity.set(0, 0, 0);
document.querySelector("#dropped").body.angularVelocity.set(0, 0, 0);
document.querySelector("#dropped").body.rotation.set(40, 45, 0);
});
</script>
</html>
【问题讨论】: