Happy #TutorialTuesday Unity Devs! This week I’m back with another AI Series video! Look forward to new videos every week on the LlamAcademy channel!
In this tutorial I show you how to make NavMeshAgents attack any other objects when it comes nearby…from a distance! This is achieved with the same pattern we did in Part 6, so if you haven’t checked that out, go back to AI Series Part 6 first! We use a Collider and OnTriggerEnter to gather attackable objects, then we use Physics.Spherecast to determine if that enemy has line of sight to that target. Once the enemy does have line of sight, we spawn bullets from an ObjectPool that travel towards the player using Rigidbody physics. I also cover how Physics.Spherecast works for those who are unfamiliar.