Detect if player is inside entity

So what I have in my game is a bog box that is disabled so the player can’t see it. I also have no collision on it so the player could walk through it. If the player enters the box, a certain sound will play. If the player exits the box. the sound will stop. Does anyone know how to do this?

Hi @Mason_Rocchio,

You can do that easily using collision triggers.

Check this example, it shows how to do that:

https://developer.playcanvas.com/en/tutorials/collision-and-triggers/

But I don’t have a collision on my entity so the player can walk through it. I am not adding a trigger because I have to optimize the game or else it won’t launch or lag bad and crash.

The trigger doesn’t provide collisions, so the player will still be able to walk through it.

I’m not sure how much performance you gain by not using triggers. If you are adamant to not use them, an alternative would be to use bounding boxes. You will have to do some manual work to setup them up and check per frame against the position of the player. Here is an example, it’s used for picking but it may be helpful:

https://developer.playcanvas.com/en/tutorials/entity-picking-without-physics/

Because it does not have a rigidbody. But the collision to activate it will crash the game.

Triggers don’t need rigid bodies. Why will it crash the game?

I have a lot of stuff in my game so chrome runs out of memory and it wont load if I add to much to the game

Ah I see, then most likely you need to do other optimizations too.

Like what?

You will have to profile and optimize your game, check this manual section for some advice on that:

https://developer.playcanvas.com/en/user-manual/optimization/