AI Patrolling enemy in Unity 2D - Tank game tutorial P10

In this Unity 2020 tutorial we will learn about creating a Patrolling enemy AI. It will follow a predefined path and stop to shoot when the Player is in range. I also briefly explain how we are using strategy pattern to implement a very simple and extendable ai system. This is part of the 2D Top Down Tank game tutorial series. Playlist • Top Down 2D Tank Game
00:00 Introduction
00:36 Recap
01:09 Strategy pattern
02:43 Implementing Strategy pattern
05:07 Patrol path script
06:34 Showing path using gizmos
09:44 Getting closest path position
11:47 Getting next path position
12:29 Follow path AI behaviour
17:29 Rotating enemy vector Dot product
18:19 Rotating enemy vector Cross product
20:06 Patrolling enemy
23:19 Support me maybe?
Resources
Scripts and UnityPackages: github.com/SunnyValleyStudio/...
Full project: drive.google.com/drive/folder...
Would you like to learn how to make a 2d shooter in Unity?
courses.sunnyvalleystudio.com/
You can support me through Patreon:
/ sunnyvalleystudio
Assets used:
www.kenney.nl/assets/topdown-...
github.com/sparklinlabs/super...
Object Pool Design Pattern article:
gameprogrammingpatterns.com/o...
Join the discord:
/ discord

Пікірлер: 6

  • @Entikai
    @Entikai9 ай бұрын

    Awesome tutorial, thanks a ton!

  • @SunnyValleyStudio

    @SunnyValleyStudio

    9 ай бұрын

    Thanks for watching!

  • @mohokhachai
    @mohokhachai6 ай бұрын

    Cool and too simple

  • @SunnyValleyStudio

    @SunnyValleyStudio

    6 ай бұрын

    Thank you! Cheers! 👍

  • @ManBung
    @ManBung2 жыл бұрын

    Hey, thanks for the tutorial! Great video! I have a question, sorry if it is a bit out of place for the youtube comment section, but how would I implement the AI following the player / moving towards the player's direction upon detecting the player.

  • @SunnyValleyStudio

    @SunnyValleyStudio

    2 жыл бұрын

    Thanks for watching! Actually using the same thinking. You need to 1) detect the player 2) find the direction towards the player (the same as we do here) and 3) move the agent / enemy towards the player. The last part is usually a bool flag "playerInSight" and "tooFarFromPlayer". In ex Update you check both flages. if player gets away you stop movement. Next you check: (Vector3.Distance(player,enemy) > minDistance) -> move else stop. The movement itself is just using the speed that you set and the normalized direction towards the player. If you want a more advanced setup that detects obstacles you need to explore A* (any pathfinding algorithm) or steering behaviors. I don't have a specific series yet about those but check Sebastian Lague kzread.info/dash/bejne/X4BhucmEfanbmKg.html