How can I make HP lower once the camera collides with a specified object?

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. :confused:

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”.:confused:

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.
shows how to fix your current build to not error out anymore and puts the collision check in

1 Like

id suggest looking into object.physicsImpostor.physicsBody.addEventListener(“collide”, e => console.log(‘collide’)); if everything has physics imposters on them.

1 Like

worked perfectly with my retry. here’s the link if you wanna see it

thank you so much!!!