简体   繁体   English

cannon.js记录碰撞而不碰撞

[英]cannon.js registering collision without colliding

I'm creating simple car game with cannon.js and I'm struggling with this. 我正在用cannon.js创建简单的汽车游戏,我正在努力解决这个问题。

What I want to do: 我想做的事:

When I run with car into another object (eg sphere) I want to know about it. 当我驾驶汽车进入另一个物体(例如球体)时,我想知道它。

For example increase score or whatever, but without applying forces to both objects. 例如,增加分数或其他,但不对两个对象施加力。

What I unsuccesfully tried: 我不成功的尝试:

Use 使用

chassisBody.addEventListener("collide",function(e){ "mycode"};

with combination groups 与组合小组

var GROUP1 = 1; etc..

but point of groups I guess is mark which object I want and don't want to collide, and I want them to "collide" but without actually applying forces to them, only registering that their bodies intersected and firing my scoring code etc. 但我认为群组的点是标记我想要的对象并且不想碰撞,我希望它们“碰撞”但是实际上没有对它们施加力,只记录他们的身体相交并发射我的得分代码等。

( I added threejs tag just in case someone might have stumbled across this, and I'm using it anyway ) (我添加了三个标签以防万一有人可能偶然发现了这个问题,而且无论如何我都在使用它)

The following code is taken from this example. 以下代码取自示例。 I tested with your event listener callback and it worked fine. 我测试了你的事件监听器回调,它工作正常。

Set collisionResponse of the rigid body to 0 : 将刚体的collisionResponse设置为0

b2.collisionResponse = 0; // no impact on other bodys
b2.addEventListener("collide", function(e){ console.log("sphere collided"); } );

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM