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 |
Beta Was this translation helpful? Give feedback.
Answered by
ChrisAcrobat
Aug 16, 2023
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 |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
ChrisAcrobat
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Solved it by: (semi-pseudo, minimized for proof-of-concept)
If someone have a better solution for
s1.shapes[0].radius + s2.shapes[0].radius
, then I'm all ears.