【发布时间】:2018-07-30 15:42:51
【问题描述】:
我正在使用a-frame physics component 使用来自cannon.js 的applyImpulse 方法“推送”框。
当使用auto 身体形状时,这工作正常,但是当我手动创建形状时,我收到以下错误
Uncaught RangeError: Maximum call stack size exceeded
at LocalDriver.applyBodyMethod (aframe-physics-system.min.js:1)
at Body.body.applyImpulse [as __applyImpulse] (aframe-physics-system.min.js:1)
请看下面我的代码。
使用以下脚本
<script src="https://aframe.io/releases/0.8.2/aframe.min.js"></script>
<script src="https://cdn.rawgit.com/donmccurdy/aframe-extras/v4.1.2/dist/aframe-extras.min.js"></script>
<script src="https://cdn.rawgit.com/donmccurdy/aframe-physics-system/v3.1.1/dist/aframe-physics-system.min.js"></script>
这是我添加到盒子中的组件。
AFRAME.registerComponent('push', {
dependencies: ['keyboard-controls'],
multiple: true,
init: function(){
this.el.addEventListener('body-loaded', () => {
this.el.addEventListener('keydown:KeyP', () => {
var force = new CANNON.Vec3(0, 0, -20)
var local = new CANNON.Vec3(0, 0, 0)
var worldVelocity = this.el.body.quaternion.vmult(force);
this.el.body.applyImpulse(
worldVelocity, local
);
});
});
},
})
以及带有方框的 HTML,显示了我添加正文的不同方式
<a-scene physics="debug:true">
<!-- auto body shape -->
<a-box
id="test1"
push
dynamic-body
position="-1 1 -3"
color="blue">
</a-box>
<!-- manual body shape -->
<a-box
id="test2"
push
body="type: dynamic; shape: none"
shape="shape: box; halfExtents: 0.5 0.5 0.5"
position="1 1 -3"
color="green">
</a-box>
<a-box
id="floor"
static-body
width="50"
depth="50"
height="0.2"
color="grey">
</a-box>
</a-scene>
And here is a glitch 来演示问题。如果您按P,您将看到蓝色框被按下,但绿色框抛出错误。除了体型之外,它们都是一样的。
盒子是问题的一个简化示例,因此在这种情况下我当然可以只使用auto 形状,但有两个原因我希望能够推动具有手动创建形状的主体。
所以我可以将自定义形状添加到自定义模型并推送它们。
我注意到,如果您将子实体添加到具有动态主体(具有自动形状)的实体,它会扩展主体的大小(这可能是我所期望的)但有些情况我想要形状保持不变。
非常感谢任何帮助。
【问题讨论】: