I want NPC soldiers to fight other NPC soldiers, but there are obstacles, so I want to raycast or something to make sure that the NPCs have lines of sight to each other. What is the best, most-optimized way to look for nearby targets? I don’t wanna spam raycast 30 times a second for 40 soldiers at once.
how about welding an invisible giant sphere to every npc and touched event in it ?
when that event launches it makes sure that what touched it is an npc, then it shoots a raycast to it.
just a basic idea
1 Like
First, do you need all of the info? Can you just stop after the first one that’s free?
Second, raycasts are really fast. If you used a whitelist and didn’t cast literally every frame, the performance wouldn’t be terrible.
If there’s a maximum range, you can also check that before you raycast.
1 Like
Oh! I forgot about whitelists! Thank you!