嗨,我是刚接触aframe的人,正在尝试进行b / w 2碰撞检测,这两个物体都带有静态物体。
我不解释为什么事件碰撞没有被触发,因为它的工作正常是1个动态和1个静态物体,而不是2个静态物体。
请提出一种使用非物理方法检测b / w 2静态碰撞体的方法,或者是否有其他方法可以让我知道。
我正在使用setInterval()
移动静态物体,并使用setAttribute('position','x y z');
更改其位置
在此先感谢一吨。
最佳答案
从 a-frame physics documentation:
静态物体:固定位置或动画对象。其他物体可能
与静态物体碰撞,但是静态物体本身是
不受重力和碰撞的影响。
静态物体不受碰撞影响。
如果它们不能动态变化,我建议跟踪它们的位置和音量,并检查它们是否发生碰撞(对于原始对象应该很容易)。
如果您有两个球体(s(x1,y1,z1)和s2(x2,y2,z2)),则可以在场景中添加一个主组件,使用2个点之间的简单距离来检查它们之间的距离formula :
tick:function(){
if(Math.sqrt(Math.pow((x1-x2),2) + Math.pow((y1-y2),2) + Math.pow((z1-z2),2)))<(sRadius+s2Radius)){
//do stuff when spheres collide
}
}
据我所知,Three.js有其自己的相交方法,您可以在here中找到它们(方法:
intersect()
,intersectsBox()
等)。要访问three.js对象,请获取el.object3D
参考。相交对象的定义如下:
{ distance, point, face, faceIndex, indices, object }
distance – distance between the origin of the ray and the intersection
point – point of intersection, in world coordinates
face – intersected face
faceIndex – index of the intersected face
indices – indices of vertices comprising the intersected face
object – the intersected object
如three.js documentation中所述。
对于其他图元的交集,您将需要研究交集的算法,因为我脑中的算法效率极低。