问题描述
我在 Aframe 中的两个实体位于不同的 AR 标记上,并希望在它们发生碰撞时触发某个功能.我添加了
非常感谢!
更新 1
它也可以在 Ar.js 标记上工作吗?
解决方案 sphere-collider
应该发出带有交叉点详细信息的 hit
事件.
拥有一个带有碰撞器的实体:
<a-球体></球体>
您可以在球体上监听 hit
和 hitend
事件,以检测碰撞何时发生以及何时结束
this.el.addEventListener('hit', (e) => {控制台日志(e)})this.el.addEventListener('hitend', (e) => {console.log('hitend')控制台日志(e)})
在此处查看.
Ngo Kevin 的 aabb-collider 似乎有效ar.js
很好(fiddle).虽然它有一个 hitstart
而不是 hit
事件.
I have two entities in Aframe on different AR Markers and would like to trigger a certain function on their collision. I've added Aframe-Extras to make use of the Sphere-Collider Module. Unfortunately I couldn't find any documentation for it.
How would I link to objects and call a global function on their collision? I guess I need to bind it somehow via js?
My current html looks like this:
<a-scene embedded arjs='trackingMethod: best; sourceType: webcam; debugUIEnabled: false; patternRatio: 0.7;'>
<a-marker preset='custom' type='pattern' url='patterns/1.patt'>
<a-box sphere-collider color="navy" depth="1" height="1" width="1" position="1 0 0"></a-box>
</a-marker>
<a-marker preset='custom' type='pattern' url='patterns/2.patt'>
<a-sphere sphere-collider color="blue" position="1 0 0" radius="0.5"></a-sphere>
</a-marker>
<!-- add a simple camera -->
<a-entity camera></a-entity>
</a-scene>
Thanks a lot!
Update 1
Can it also work on Ar.js Markers?
<a-marker preset='custom' type='pattern' url='patterns/1.patt'>
<a-box position="-1 0.5 -3" rotation="0 45 0" color="#4CC3D9" foo></a-box>
<a-sphere sphere-collider='' position="3 0.5 -3" radius="0.25" color="#EF2D5E">
<a-animation attribute="position" dur="5000" fill="forwards" to="-1 0.5 -3" repeat="indefinite"></a-animation>
</a-sphere>
</a-marker>
Find a fiddle here:https://jsfiddle.net/jk4gbu13/5/
解决方案 The sphere-collider
should emit a hit
event with intersection details.
Having an entity with the collider:
<a-box sphere-collider></a-box>
<a-sphere></sphere>
You can listen on the sphere for the hit
and hitend
events to detect when the collision occured, and when it ended
this.el.addEventListener('hit', (e) => {
console.log(e)
})
this.el.addEventListener('hitend', (e) => {
console.log('hitend')
console.log(e)
})
Check it out here.
Ngo Kevin's aabb-collider seems to work fine with ar.js
(fiddle). Although it has a hitstart
instead of hit
event.
这篇关于Aframe Sphere-Collider 碰撞触发功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!