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
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
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.
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 :(
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 ?
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
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
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.
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?
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.
@@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.
@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.
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.
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.
@@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.
@@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
@@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 .❤
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!
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. 😃
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
Your tutorial came in clutch. Thank you so much!
Class vedio. Just what I needed! Thanks a mill!
Glad it helped!
How can you animate them so that they look like they’re walking?
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
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.
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 :(
My enemy just walk in the obstacles, any solution?
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 ?
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
Hey , how can I make it stop for a few seconds please 🥺🥺🥺🥺
Ummm
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
@@kleine.hooligan No I didn’t, sorry
Enemy gets stuck when reaching the corners or edges of the navmesh. how do I fix that?
Chat gpt
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.
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?
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.
@@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.
were you able to fix it? I'm having the exact same problem
@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.
How did you do that? Can we get a small tut. Seems like everyone is having that problem@@bmpproductions
this was very usefull, ty bro
How to create a stop value after reaching a random location
Can you make a copy and paste script?
The AI keeps flying?!
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.
I need it but for NPC but in array.Because NPC will spawn and array will handle randomly spawned NPC index.
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.
@@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.
@@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
@@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 .❤
You are relly good thenk you so match
you are great!!
pay walled code :(
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!