forked from schteppe/cannon.js
-
Notifications
You must be signed in to change notification settings - Fork 155
How do I get bodies that are not intersected? #186
Answered
by
ChrisAcrobat
ChrisAcrobat
asked this question in
Q&A
I spawn a random amount of Bodys at a single point with collisionResponse=false. This is what I want, but what I also want is to enable collisionResponse when each object has left the group after .fixedStep(n).
Is there an in-engine or native way of solving this? I have tried using collisionMatrix and event handler, but have not got it to work yet,
All reactions
Answered by
ChrisAcrobat
Aug 16, 2023
Solved it by: (semi-pseudo, minimized for proof-of-concept)
const spheres = []; let nextID = 1; const target = Math.random()*100; for(let i= 0; i < target; i++) { const collisionFilterGroup = nextID; const collisionFilterMask = 0; spheres.push(new Sphere({collisionFilterGroup, collisionFilterMask})); nextID *= 2; } while(true){ world.fixedStep(1); spheres.forEach(s1 => { spheres.forEach(s2 => { const touchPoint = s1.shapes[0].radius + s2.shapes[0].radius; if(touchPoint < s1.position.distanceTo(s2.position)){ s1.collisionFilterMask |= s2.collisionFilterGroup; } }); }); }
If someone have a better solution for s1.shapes[0].radius + s2.shapes[0].radius, then I'm all ears.
Replies: 1 comment
Solved it by: (semi-pseudo, minimized for proof-of-concept)
const spheres = []; let nextID = 1; const target = Math.random()*100; for(let i= 0; i < target; i++) { const collisionFilterGroup = nextID; const collisionFilterMask = 0; spheres.push(new Sphere({collisionFilterGroup, collisionFilterMask})); nextID *= 2; } while(true){ world.fixedStep(1); spheres.forEach(s1 => { spheres.forEach(s2 => { const touchPoint = s1.shapes[0].radius + s2.shapes[0].radius; if(touchPoint < s1.position.distanceTo(s2.position)){ s1.collisionFilterMask |= s2.collisionFilterGroup; } }); }); }
If someone have a better solution for s1.shapes[0].radius + s2.shapes[0].radius, then I'm all ears.
All reactions
0 replies
Answer selected by
ChrisAcrobat
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment