简体   繁体   中英

cannon.js registering collision without colliding

I'm creating simple car game with cannon.js and I'm struggling with this.

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 :

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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