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.

2 Likes

I tried but when I put “if (hitbox.intersectMesh(sphere)){ hp - 10}”, it says “hitbox.intersectMesh is not a function”.:confused:

https://playground.babylonjs.com/#Z620GV#11

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

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

https://playground.babylonjs.com/#A2LQK1

thank you so much!!!