How to detect if two entity's are near each other

I have 100+ monster entity’s, and a player entity. I need to know when the player gets close to one of the monster entity’s. I dont want to compare their current position against my players because there are so many of them; also doing ray casts in every direction every frame seems overkill and not very effective. Whats the fastest and most reliable way to do this.

Hi @Austin_Michaud,

Not sure if you can get away with comparing their position against the player’s. Though that wouldn’t be slow if you are doing it for ~100 entities. Also to improve performance you can do the check once every couple of frames (e.g. 3-4 times every second) if your gameplay can get away with some lose of precision (instead of per frame).

No need for raycasts/physics. You can set up a pc.BoundingSphere for your player and each monster entity, to your desired radius, loop over your monster entities and check for each if the bounding spheres intersect.

If that’s true, then the player is close to that monster.

Is there an advantage to using a bounding sphere instead of a bounding box?

Yeah, a sphere is a homogenous shape around a central point and is ideal for distance checking.

You can use a box, as well, but you will not get the same distance when closing on a monster on different approach angles.