How to Make A Randomly Walking A.I. in Unity

Поділитися
Вставка
  • Опубліковано 29 жов 2024

КОМЕНТАРІ • 40

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

    Thank you very much you’re so kind for making this project. I want to use this on VR chat for fun and see what I could make for fun. 😃

  • @RiceisGud_
    @RiceisGud_ 2 дні тому

    do you know how to allow for the player to jump when applying the NevMeshSurface to the ground, i was able to jump before applying the mesh surface, everything else regarding the program works though so cheers for that

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

    Your tutorial came in clutch. Thank you so much!

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

    Class vedio. Just what I needed! Thanks a mill!

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

    How can you animate them so that they look like they’re walking?

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

    hey great video. just wondering how i could change the color of text in my code. like how when u type Vector3 or range and raycast it changes colour, because mine just stays normal, like white
    ALSO i have no idea why but my ai just starts flying away when i press play

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

    Hi @The Game Dev Cave, i followed your script and tutorial and the enemy only moves along the z axis and it only moves on the x axis at the beginning until it reaches the z line that it wants to follow ( seems to be 0 x).
    Do you know why that is and how to fix it? also whenever it looks for random destination it seems to spam...it can happen one or twice per second.

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

      There seems to be something buggy with the AI navigation because sometimes it works properly, other times the enemies don't move at all at the start of the game. Restart the game and now they chase you but they don't attack and so on.
      I really hope there's a fix for that, i only need my game to be set up like you show in your tutorials but i can't even have that :(

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

    My enemy just walk in the obstacles, any solution?

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

    Hey nice video but I am getting an error "NullReferenceException: Object reference not set to an instance of an object" for the setdestination in the patrol function . What should I do ?

    • @thegamedevcave
      @thegamedevcave  7 місяців тому +1

      that error means that you're not setting a value to the object youre trying to use. so whatever object you're trying to do something with in that function isn't getting set correctly

  • @muneebhero1159
    @muneebhero1159 4 місяці тому +1

    Hey , how can I make it stop for a few seconds please 🥺🥺🥺🥺

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

    ok so for some reason when I look at components I can't find Nav Mesh agent, I've looked in components and window does anyone know where it is I'm using 2022 version

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

    Enemy gets stuck when reaching the corners or edges of the navmesh. how do I fix that?

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

      Chat gpt

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

      Actually, the problem is that destination point is not set on the groundlayer. the raycast, if it hits any object with groundlayer, just below, the if statement is getting true, and, it is not checking whether it is in the walkable area or not. Now the navmeshsurface takes all area under it, but does not check whether the area is walkable or not. so groundlayer collision is true, but you can't reach that place.
      so the best action is to the hitpoint of the raycast as the destination point.

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

    So, question? When i have obstacles in the scene, the NavMeshAgent works with the script mostly but the waypoint it sets can get stuck in the part between the obstacle and NavMeshSurface and then the NavMeshAgent just starts glitching out and doesn't move. I just wanted to know if you knew what that issue could be from?

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

      Mavmashes can be a bit weird sometimes. you could try to regenerate the navmesh and see if it generates around the obstacle. As far as I know, it should generate around anything with collision but adding new obstacles after generating it can cause annoying issues.

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

      @@thegamedevcave I've re-baked the Navmesh multiple times with the same obstacles in place but it always eventually tries to put a waypoint somewhere that it shouldn't like inside of an obstacle. Once that happens, the NavmeshAgent just glitches out and stays in it's place and the waypoint is just stuck inside the obstacle. I'm not sure if it's an issue with the script or something else but I double checked the script and it is exactly like in the video.

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

      were you able to fix it? I'm having the exact same problem

    • @bmpproductions
      @bmpproductions 8 місяців тому +2

      @uhgoodlex In an optimal way? No... but I did kind of just cheat the system and made it where the navmesh agents get triggered to walk in a different direction if it touches anything like walls. It works to an extent but it's certainly not optimal.

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

      How did you do that? Can we get a small tut. Seems like everyone is having that problem​@@bmpproductions

  • @DAN-gf3qx
    @DAN-gf3qx 3 місяці тому

    this was very usefull, ty bro

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

    How to create a stop value after reaching a random location

  • @Kingplays342
    @Kingplays342 3 місяці тому

    Can you make a copy and paste script?

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

    The AI keeps flying?!

    • @artisethistoria4269
      @artisethistoria4269 8 місяців тому +1

      Super late but I got a fix: I have to NOT set the NavMeshSurface as a component of the enemy/AI as done here but have to set it as a component of an unrelated object. I have an empty empty object I called "GameManager" that holds the NavMeshSurface component so that this does not move with the AI. I then had random issues with the AI sometimes just not moving at all or stopping randomly?? In the end I ended up using a script that makes the AI randomly walk within the radius of a set object within the scene. There is a video called "Random AI Patrolling Tutorial Unity3D" that shows a script that seems useful for this. It works 100% fine for me now but boy... took me a few hours.

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

    I need it but for NPC but in array.Because NPC will spawn and array will handle randomly spawned NPC index.

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

      should be easy enough to change up the script to work on whatever NPC manager you have to set the destination points of each navmesh agent.
      just loop through the array on the NPC manager/ spawner (whatever you use) and call the FindWalkPoint fuction (make sure it's public) on each NPC that has it's walkPointSet bool as false.

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

      @@thegamedevcave Thanks bro. This video solved half of my problems. Is there any efficient way that NPC can interact with each other or player like any Open world Games. Grouping together or doing activities? I have no idea how to do that.

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

      @@alexpurification1260 Good question, heavily depends on what you need them to do and whatever existing code you already have. if you just need them to hang out together in groups I suggest a system where you can put down empty gameobjects that you can reference as a " meeting spot" and when an NPC is near one it'll check how many other are already an that spot, if there is room (let's say a spot can have up to 10 NPCS) it'll walk to a random spot in a range of that spot and trigger a function to add itself to a list on the meeting spot that keeps track of the NPCs that are on it, then set a random timer for when they should walk away, at which point it'll remove itself from that list again and go on with it's normal wandering behavior or whatever it was doing before.
      then, if you need a group to do anything, you have a list of all the NPCs that belong to that group so you can do anything you'd like from there. , say make all of them aggressive towards you if you hit just one of them or something.
      Long story short, it can get pretty complex but that's the basic shape of how i'd build a system like with

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

      @@thegamedevcave I must try this bro. But whenever I'm thinking about code logic of it my brain said "Come on dude! It's nothing here" 😅. BTW i understand what i need to do now after reading carefully your words. Thank you bro. It was really informative .❤

  • @NikolayAvanesyan-j5l
    @NikolayAvanesyan-j5l Рік тому

    You are relly good thenk you so match

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

    you are great!!

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

    pay walled code :(

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

      You can follow al along with the tutorial and get the dame redults. The project files only serve as an extra aid and come with premade models amd animations :) the patreon gives you access to every project file ive uploaded, not just this one too!