【发布时间】:2020-12-02 18:44:09
【问题描述】:
我正在尝试捕捉动态球体和静态 gltf 模型之间的碰撞事件。我正在通过以下方式构建 gltf 实体:
const template = document.createElement('a-entity');
template.setAttribute('physics-collider', 'ignoreSleep: false');
template.setAttribute('collision-filter', 'collisionForces: false');
template.setAttribute('body', 'type:static; shape:hull');
// add position, scale, url etc
// ...
template.addEventListener('collisions', e => {
// debugger;
})
这段代码创建了一个实体,但在调试模式下它周围没有网络,并且collisions 事件没有被触发。
出于调试目的,我尝试了不同的形状。这会在实体周围创建一个圆柱体,但它看起来太大了。动态形状穿过圆柱体,但并非总是触发 collisions 事件,相当罕见。
template.setAttribute('body', 'type:static; shape:cylinder');
然后我尝试手动构建形状:
template.setAttribute('body', 'type:static; shape:none');
template.setAttribute('shape', 'shape: cylinder; height: 5;');
在这种情况下,我收到以下错误:
Cannot read property 'bodyOverlapKeeper' of null at NewComponent.<anonymous> (physics-collider.js:34)
所以现在我被困住了。有人可以建议我做错了什么。我想使用 gltf 模型本身的形状。我用blender打开了,好像还可以,不明白shape:hull为什么不行。
P。 S.:如果重要的话,我正在使用 webpack
【问题讨论】:
标签: javascript game-physics aframe