Random AI Patrolling Tutorial Unity3D

Поділитися
Вставка
  • Опубліковано 15 лип 2022
  • In this video I will teach you how to make a navmesh agent move around randomly within an area.
    Code (yes you can use it for whatever you want): github.com/JonDevTutorial/Ran...

КОМЕНТАРІ • 79

  • @JulianSanchez-fk7ly
    @JulianSanchez-fk7ly Рік тому +20

    I have been watching videos longer than 20 minutes.
    And literally the one that helped me was a 2 minute long video with memes.

  • @nikjeewon4672
    @nikjeewon4672 Рік тому +4

    Thank you for this. Love the short and straight to the point ones :)

  • @a3dadventure79
    @a3dadventure79 11 місяців тому

    nice job - it's a really simple yet essential bit of ai coding. thanks for putting this up and keeping it simple. more of this = gold !

  • @patrickalexander8066
    @patrickalexander8066 Рік тому +4

    The sims build mode music is the cherry on top, beautiful!

  • @madduckling4436
    @madduckling4436 Рік тому +20

    I don't use Unity at the moment but I understand the logic behind some of the things you're teaching and I transfer what I learned to GDscript you deserve a sub you deserve a like and you deserve my attention for every video you upload.... one day when i reuse unity I'll be rewatching all of the videos aswell!

    • @jondevtutorials4787
      @jondevtutorials4787  Рік тому +9

      Thanks beast, nice job on transferring the knowledge over to something else, it's a good skill to have.

  • @inimagames
    @inimagames 6 місяців тому

    Simple, but straightforward and very useful! Thanks a lot for the help! 💪

  • @LordVilmore
    @LordVilmore Рік тому +3

    so much value in such little time. impressive!! most tutorials would need 16 minutes for this... uggggggh

  • @angelkaki5707
    @angelkaki5707 7 місяців тому

    Finally somebody who goes straight to the point even tho the script was in unity xD!!! now i guess its time to work on a way to have the enemy chase you and attack but if the player leaves the area after a certain distance the mob will go back to its original spot

  • @nicholasnui6630
    @nicholasnui6630 Рік тому +1

    Subscribing just for the upbeat music at a reasonable level in the background

  • @davidgil1171
    @davidgil1171 2 роки тому +4

    Thanks for this!!! I really lovethe format of your videos, just keep it up! Day 2 of asking for a simpler Inventory system btw

  • @naosabes2589
    @naosabes2589 Місяць тому

    "It is legally required to like the video, you dont wanna end up like this guy" 😂😂😂😂😂😂

  • @unDeadGod69
    @unDeadGod69 2 місяці тому

    Really good tutorial, thanks for the help

  • @vannerss7287
    @vannerss7287 Рік тому +2

    If you don't subscribe after watching such an eloquent tutorial, pls don't make games.

  • @offsider_
    @offsider_ Рік тому +1

    Easy to follow, informative and fucking funny had to subscribe!

  • @Cyberinfinitystudio
    @Cyberinfinitystudio 16 днів тому

    This is so good for my game thanks

  • @renaisol
    @renaisol 5 місяців тому

    very useful! gonna save it for next project XD

  • @dangboor4277
    @dangboor4277 11 місяців тому

    Thanks my good sir

  • @whitetiana3022
    @whitetiana3022 Рік тому +3

    this reminds me of my time in uni.
    they didn't bother to explain anything either.

  • @junaidjamshed8104
    @junaidjamshed8104 Рік тому +1

    Love it

  • @hirayukisei3813
    @hirayukisei3813 5 місяців тому

    Thank you so much.

  • @gyrostat5211
    @gyrostat5211 Рік тому

    cool stuff dude

  • @thesaviorofsouls5210
    @thesaviorofsouls5210 7 місяців тому

    Awesome, this helped me so damn much. Appreciate it, have a like as by contract ;P

  • @beshkekart3909
    @beshkekart3909 Рік тому +1

    GEENIUSSS!!!!

  • @marinavlachandreas5197
    @marinavlachandreas5197 Рік тому +1

    It works :)

  • @Dev_Roids
    @Dev_Roids 7 місяців тому

    Thanks sooo much

  • @xrxsever
    @xrxsever Рік тому +1

    tnx mate

  • @BlueAndy_
    @BlueAndy_ Рік тому

    thanks man

  • @kingawesomeness1239
    @kingawesomeness1239 5 місяців тому

    thank you

  • @grkpektis
    @grkpektis Рік тому +5

    Please help, he just stops at the middle

  • @user-dw6es7zg8z
    @user-dw6es7zg8z Місяць тому

    Danke

  • @farziverse4209
    @farziverse4209 9 місяців тому +1

    How do I give logic to the randomness. Such that the agent may run away from player in a random zig-zag manner

  • @jasonwilliams8730
    @jasonwilliams8730 Рік тому +1

    Like👍

  • @cosminwheelz2597
    @cosminwheelz2597 9 місяців тому

    Hello there! Is it mandatory to bake both the surfaces from the navmeshSurface component and also from the navMeshAgent?

  • @leonbierling4857
    @leonbierling4857 Рік тому

    How can I make the NPC fly up and down with this? (By setting layers of baked navmash for instance)

  • @Airelon
    @Airelon Рік тому +1

    Obligation fulfilled🤪

  • @catbushi1756
    @catbushi1756 9 місяців тому

    Where can I find the navmesh agent and what should I put in the boxes: "Agent, Range and Centre Point" ?

  • @SamPlayz9716
    @SamPlayz9716 Рік тому

    what do i set for centre point

  • @wmka
    @wmka Рік тому +2

    I'm thinking of making random movements for cockroaches.
    How do I make them move from floor to wall to ceiling?
    Thank you and have a good one

    • @jondevtutorials4787
      @jondevtutorials4787  Рік тому +4

      You will probably want to create a custom navmesh, and make sure you orient the cockroaches to the normals of your surface.
      Here is a good video: ua-cam.com/video/bl9_bRZs0Gg/v-deo.html&ab_channel=El-Capitan

  • @Kapra_crow
    @Kapra_crow Рік тому +2

    Is there any way I could make so if the enemy detects the player it sets the player as the destination?

    • @zacharmy8948
      @zacharmy8948 Рік тому

      What you could do is make a public Transform variable and set the player's transform to that variable. If you are going for an automatic range detect system, you can get the distance between the player and the NavMeshAgent by using Vector3.Distance() and pass in the two arguments.
      Then you can create a float variable which will determine the detection range. Next, you can use an if statement to check whether the distance between the AI and the player is less than the range variable. If the player is in range you can call the NavMeshAgents's SetDestination() function and pass the player's position as an argument.

  • @FakeMrFlimFlam
    @FakeMrFlimFlam Рік тому

    Hello, thanks for this tutorial. But what do you put in Centre Point ? Thanks

    • @jondevtutorials4787
      @jondevtutorials4787  Рік тому +1

      Just create an empty gameobject and use that. Position the empty gameobject on the floor of the navmesh.

  • @jaydaykoth
    @jaydaykoth 4 місяці тому

    Does anyone have any ideas on how to play walking animations for humanoid npcs

  • @user-ly2zr3hr3v
    @user-ly2zr3hr3v 3 місяці тому

    what do i do with the navmesh? i somehow cant get it to work

  • @jarrydoneill7834
    @jarrydoneill7834 Рік тому

    How could I implement this in 2D?

  • @foxys891
    @foxys891 Місяць тому

    he dosent move for me or just me being dumb it was helpfull but dosent walk for me maybe im just missing some thing cause i just threw in the script the navmesh baked it and still doset move

  • @cxd1
    @cxd1 Рік тому

    Can you make something like this but with a car ?

  • @dertobbe1176
    @dertobbe1176 11 місяців тому

    My agent get stuck at destination point. He wont finish the path

  • @vinnythehusky3481
    @vinnythehusky3481 День тому

    Question does anyone know how to make it work on VRCHAT?

  • @rasulkhani
    @rasulkhani 7 місяців тому

    I added an empty game object and put it as the center point but the AI just moves to the center point and stops, is there anyway I can fix this?

    • @miquelsunyerroda9638
      @miquelsunyerroda9638 4 місяці тому

      have you implemented a navmesh surface?
      bool RandomPoint(Vector3 center, float range, out Vector3 result)
      {
      Vector3 randomPoint = center + Random.insideUnitSphere * range; // Punto aleatorio en una esfera
      NavMeshHit hit;

      if (NavMesh.SamplePosition(randomPoint, out hit, 1.0f, NavMesh.AllAreas))
      {
      result = hit.position;
      Debug.Log("Random Point: " + result); // Mensaje de depuración con las coordenadas del punto
      return true;
      }
      result = Vector3.zero;
      Debug.Log("SEARCH FOR POINT FAILED"); // Mensaje de depuración si la búsqueda del punto falla
      return false;
      }
      Change the Bool for this one, it will print on the console if there is a point found or not and the position of the random generated point

    • @rasulkhani
      @rasulkhani 4 місяці тому

      @@miquelsunyerroda9638 ok thx it works now

  • @StucWf
    @StucWf Рік тому +2

    I'm definitely doing something wrong. I applied the script to a capsule but nothings happening

  • @spai_wolf8561
    @spai_wolf8561 Рік тому +1

    Hello brother can we reduce the stoping time between the points?

    • @jondevtutorials4787
      @jondevtutorials4787  Рік тому

      Hello brother,
      Play with your navmeshagent settings in the inspector. Try increasing acceleration, disabling autobreaking etc.
      Best of luck

    • @spai_wolf8561
      @spai_wolf8561 Рік тому

      @@jondevtutorials4787 i will try and see

    • @michaelmalard8145
      @michaelmalard8145 8 місяців тому

      ​@@spai_wolf8561 Did it works? And what did you change ??

    • @reedwitch9246
      @reedwitch9246 23 дні тому +1

      I don't think this will help, since you wrote the comment a long time ago, but maybe it will help someone else who will continue to use this tutorial!
      private float nextActionTime = 0.0f;
      public float period = 0.1f;
      void Update()
      {
      if (Time.time > nextActionTime)
      {
      nextActionTime += period;
      //part of the original script begins
      if (agent.remainingDistance

  • @vladaslittleparadise4402
    @vladaslittleparadise4402 Рік тому

    im having a problem... so it works at the start... but i notiched that after following the first waypont it stops moving ... so i started looking at it in the editor view and only a waypoint apperars... after that the agent just spins (int the script component i put the agent im using, for the Range value i put 20 and for the Centre point i put the floor im using)

    • @jondevtutorials4787
      @jondevtutorials4787  Рік тому +1

      If you copied the code exactly from the GitHub it may be a problem with your NavMeshAgent component. For example, the navmeshagent stopping distance could be too large. Or maybe it's a problem with the navmesh not being baked properly.

    • @vladaslittleparadise4402
      @vladaslittleparadise4402 Рік тому +1

      @@jondevtutorials4787 i managed to fix the problem... thank you very much

    • @se5d
      @se5d Рік тому

      @@vladaslittleparadise4402 i`m having the same problem.. what did you change?

    • @vladaslittleparadise4402
      @vladaslittleparadise4402 Рік тому

      @@se5d nothing really... I just re-did it

    • @bluntbangs
      @bluntbangs 9 місяців тому

      @@jondevtutorials4787 Just to clarify as someone who had the same issue, you have to set the "Range" above 0, or else the agent will just move straight toward the centre point.

  • @akamaraasho
    @akamaraasho Рік тому

    How can I make it work in a 2D game?

  • @Hunter-X9211
    @Hunter-X9211 28 днів тому +1

    At least explain the code properly that what will be the values and how can we stop agent when he reached the point he just run here and there

  • @jackmarquette1351
    @jackmarquette1351 Рік тому

    I can’t read

  • @julianrockl4228
    @julianrockl4228 Рік тому +1

    Too lazy for waypoints it is.

  • @foreignwarren7361
    @foreignwarren7361 Рік тому +1

    Can this work for 2D?

  • @supersentaimexicano1967
    @supersentaimexicano1967 Рік тому

    Is there a way to visualize the Range that the MOnster have ?