Hi!
Is there any way to check if an object is intersecting any mesh in the scene? I don’t want to type out sphere.intersectsMesh(sphere1, false)
a million times.
Thanks!
Hi!
Is there any way to check if an object is intersecting any mesh in the scene? I don’t want to type out sphere.intersectsMesh(sphere1, false)
a million times.
Thanks!
You could try something along the lines of
for (var i = 0; i < scene.meshes.length; i++) {
if (sphere !== scene.meshes[i]) {
sphere.intersectsMesh(scene.meshes[i], false);
}
}
I did some playing around with multiple collisions of spheres a while back. You can read some findings in the Babylon.js Documentation
A resulting PG https://www.babylonjs-playground.com/#HIM0WS#1
Thanks! works great! I’m using it in ILMBN and needed something to detect jumping. It goes like this:
for (var i = 0; i < scene.meshes.length; i++) {
if (sphere !== scene.meshes[i]) {
if (sphere.intersectsMesh(scene.meshes[i], false) && jump == true && canjump == true) {
translate(sphere, new BABYLON.Vector3(0, 0.45, 0), jumppower);
canjump = false;
}
}
}
I’m hoping this won’t slow down with a lot of meshes.