How many raycast can be running in a scene without it being considered too many?(Solved)
Simple scene... player object, a few obstacles and an enemy using raycast to detect/attack the player - All good.
Next scene... player object, a few obstacles and maybe as many as 52 enemies all using the same raycast method to detect/attack the player.
Is this going to be over-taxing on my game/resources
???
Answer by fafase · Mar 29, 2015 at 12:52 PM
Should not since Raycast is just multiplication and division of a few values.
The real question is do you need casting each frame? Could you maybe make them less frequent like only 4 times per second (already a cast each 25ms which sounds enough).
private float freq = 0.25f; // 4Hz
void Update(){
timer +=time.deltaTime;
if(timer> freq){
timer = 0;
AIMethod();
}
}
Was already thinking something the same. I was going to try a do it using random range, but your suggestion looks more efficient.
I'll give it a go implementing your script.
Thanks
:)
Well, depending on the scene, a raycast could be hundreds of lines. For example, if it's checking for the same layer as those 52 enemies and passes by lots of them, and they use $$anonymous$$esh colliders (it checks the bounding box first, but if it passes close by, it has to check the mesh, too).
Your answer
Follow this Question
Related Questions
Using Raycast2D over Tilemap? 0 Answers
Text shows in scene but not in game,Text showing in scene but not in game 0 Answers
Scene Changing changes speed of objects 0 Answers
Using 2 scenes massively hurts performance - why ? 0 Answers
Unity can't save scenes 0 Answers