Cannon.js logs collision without collision

I am creating a simple car game with cannon.js and I am struggling with this.

What I want to do:

When I run the car into another object (like a sphere), I want to know about it.

For example, increase the score or something else, but do not apply force to both objects.

What I tried unsuccessfully:

Using

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

      

with groups of combinations

var GROUP1 = 1; etc..

      

but the dot of the groups, in my opinion, indicates which object I want and do not want to collide, and I want them to "collide" but without actually applying forces to them, only registering that their bodies intersect and trigger my evaluation code and etc.

(I added the tag three tags in case someone might stumble upon it and I use it anyway)

+3


source to share


1 answer


The following code is taken from this example. I tested your answer with an event listener and it worked fine.

Set the collisionResponse

solid to 0

:



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

      

+4


source







All Articles