It seems that intersectMesh doesn’t help me. I already defined how much HP there is and what happens if you hit 0. I just don’t know how to detect the collide. “if (camera.intersectMesh(sphere)) { hp = 0 }” didn’t seem to work.
Hi. Maybe you can create simple mesh and attach as children to your camera. Because camera is not mesh and i think you can’t check camera intersection as mesh intersection.
I tried but when I put “if (hitbox.intersectMesh(sphere)){ hp - 10}”, it says “hitbox.intersectMesh is not a function”.
2 things.
1 you are using intersectMesh… it should be intersectsMesh… missed the s.
the other thing is you are running this only once on scene loading.
https://playground.babylonjs.com/#Z620GV#16
shows how to fix your current build to not error out anymore and puts the collision check in
scene.registerBeforeRender
id suggest looking into object.physicsImpostor.physicsBody.addEventListener(“collide”, e => console.log(‘collide’)); if everything has physics imposters on them.
worked perfectly with my retry. here’s the link if you wanna see it
https://playground.babylonjs.com/#A2LQK1
thank you so much!!!