Рет қаралды 22,969
Learn how to make NavMeshAgents find valid cover spots from another target object. In this video we'll specifically use a Player, but this can be applied to hide from any object - a grenade for example. Together we'll create a configurable script that allows us to refine which objects are valid to hide behind, and exclude those that are not.
We'll add the following possible configurations:
⚫ Layers of objects to consider for cover, and to hide FROM
⚫ Radius to check for objects to hide behind, and FROM
⚫ Size of objects to hide behind
⚫ Distance from object cover must be
⚫ How good of a hiding spot it must be to take cover
⚫ How frequently to check for new hiding/cover spots
💸 Ongoing sales 💸
⚫ See all active asset sales on the Asset Store: assetstore.unity.com/?on_sale...
⚫ Save 25% off your first Asset Store Order: prf.hn/click/camref:1101l9QvC...
⚫ Save up to 50% on NEW Assets: assetstore.unity.com/?new_sal...
👨💻 As always, all code from this video is available on GitHub: github.com/llamacademy/ai-ser...
❤ Believe in LlamAcademy's mission and have received value from the videos? Become a Patreon Supporter or KZbin Member:
⚫ Patreon: / llamacademy
⚫ KZbin Member: / @llamacademy or click the Join button on any video
📚 Resources:
⚫ You can also check out AI Series Part 11 where we used the Dot Product to control enemy gaining line of sight of the player: • How to Make a State Ma...
⚫ C# Comparison Delegate reference: docs.microsoft.com/en-us/dotn...
⚫ C# CompareTo reference: docs.microsoft.com/en-us/dotn...
As usual with the AI Series, we're using the NavMesh Components: docs.unity3d.com/Manual/NavMe... not the built-in navigation system.
----
Most tutorials come from knowledge gained making survival.llama.software Llama Survival - a top-down zombie survival shooter for Android and iOS.
I also have some Unity Assets (affiliate link): assetstore.unity.com/publishe...
Some links may be affiliate links, which at no additional cost to you, gives me a small portion of the purchase.
#unitytutorial #tutorialtuesday #gamedev #tutorial #unity #llamacademy #gamedevelopment #ai
Chapters:
00:00 Introduction
02:18 Scene Overview
03:12 PlayerInput.cs
03:25 EnemyLineOfSightChecker.cs - Look for Targets to Hide From
07:10 EnemyMovement.cs - Find Hiding Spots
13:42 Hooking It Up
14:23 Demo - Enemy Chooses Random Cover Spots
14:49 EnemyMovement.cs - Distance-based Ordering
15:58 Demo - Enemy Sometimes Sticks to 1 Wall
16:22 EnemyMovement.cs - Adding Minimum Distance from Target
17:07 Demo - Enemy Sometimes Chooses Too Small a Wall
17:54 EnemyMovement.cs - Exclude Objects Based On Size
18:27 Demo - Enemy Hides Effectively
19:37 EnemyMovement.cs - Throttle Hide Coroutine
20:04 Final Demo