Skip to content

How do I get bodies that are not intersected? #186

Answered by ChrisAcrobat
ChrisAcrobat asked this question in Q&A
Discussion options

You must be logged in to vote

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

Comment options

You must be logged in to vote
0 replies
Answer selected by ChrisAcrobat
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant