I’m making a 6DOF game like Descent and want some of the enemies to detect incoming projectiles and attempt to avoid them, I’m having trouble with the detection part.
I considered having all projectiles casts rays that trigger dodging movement from the AI, but it seems like a very expensive solution when there can be 50+ projectiles in a scene.
SphereCast script in a co-routine on the dodging GameObject that runs periodically (2-3) time / sec that searches the sky for in coming fire. If you put your projectiles on their own physics layer you would only need to cast against actual missiles. I use a similar approach on a mini map for grouped bot radar and it seems to do OK.
Another possible way is for the spawned projectile send a (a you’re being shot at by me) message to the targeted GameObject. The bot can then take definitive defensive action vs a known target.
I like the SphereCast idea, going to try it out. Sounds a lot more efficient too, since instead of having detection per projectile it’s only per enemy object.
I considered something like your second idea, doing a single raycast when firing along the projectile’s vector and have any AI hit react with a delay according to distance and the AI’s reaction time. Would be very cheap but not really precise.