How to Make a Ranged Attacking Enemy | AI Series Part 7




Published: 23 Mar 2021

Learn 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 (https://youtu.be/Aee01YxQIsw )! 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.


As usual with the AI Series, we're using the NavMesh Components: https://docs.unity3d.com/Manual/NavMesh-BuildingComponents.html not the built-in navigation system.


🔶 ALL THINGS LlamAcademy now available at: https://llamacademy.dev/support including latest tutorials, courses, ways to support, and more! Check it out 🙂

👨‍💻 Get the FULL FREE PROJECT on GitHub: https://github.com/llamacademy/ai-series-part-7

🏷️Save 25% on the ultimate C# IDE: JetBrains Rider with code LLAMACADEMY: https://www.jetbrains.com/store/?section=personal&billing=yearly


Some links may be affiliate links, which at no additional cost to you, gives me a small portion of the purchase.


Connect on Social Media

Some links may be affiliate links, which at no additional cost to you, gives LlamAcademy a small portion of the purchase.