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

Поделиться
HTML-код
  • Опубликовано: 13 дек 2022
  • Today we're starting off a small mini series in which we make an enemy A.I. This first part focuses on making it patrol around, something that you'll want to re-use for a lot of different NPCs in most of the games you'll end up making!
    get the Project here : / unity-3d-75458669
    Join the discord for any help you need! : / discord
    support the channel and development over on patreon : / thegamingcaves
  • НаукаНаука

Комментарии • 31

  • @BruteChief
    @BruteChief 6 месяцев назад

    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. 😃

  • @othisfoo
    @othisfoo 17 дней назад

    Your tutorial came in clutch. Thank you so much!

  • @jamescockfield422
    @jamescockfield422 3 месяца назад

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

  • @jaydaykoth
    @jaydaykoth 2 месяца назад

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

  • @rezazolgharnein7609
    @rezazolgharnein7609 10 месяцев назад

    How to create a stop value after reaching a random location

  • @vsczzzzzzzzzzz
    @vsczzzzzzzzzzz Год назад

    you are great!!

  • @user-ll3tx3ft9r
    @user-ll3tx3ft9r Год назад

    You are relly good thenk you so match

  • @Warl89
    @Warl89 Месяц назад

    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 Месяц назад

      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 :(

  • @pranshusarthak8665
    @pranshusarthak8665 Месяц назад

    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  Месяц назад

      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

  • @bmpproductions
    @bmpproductions 5 месяцев назад

    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  5 месяцев назад

      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 5 месяцев назад

      @@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 3 месяца назад

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

    • @bmpproductions
      @bmpproductions 3 месяца назад +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 Месяц назад

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

  • @budobearandfriends
    @budobearandfriends 2 месяца назад

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

  • @DP_Productions658
    @DP_Productions658 9 месяцев назад +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

  • @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 .❤

  • @Spiggifyy
    @Spiggifyy 8 месяцев назад +1

    The AI keeps flying?!

    • @artisethistoria4269
      @artisethistoria4269 2 месяца назад +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.

  • @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!