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...
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!
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
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
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.
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
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
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
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)
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.
@@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.
I have been watching videos longer than 20 minutes.
And literally the one that helped me was a 2 minute long video with memes.
Thank you for this. Love the short and straight to the point ones :)
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 !
The sims build mode music is the cherry on top, beautiful!
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!
Thanks beast, nice job on transferring the knowledge over to something else, it's a good skill to have.
Simple, but straightforward and very useful! Thanks a lot for the help! 💪
so much value in such little time. impressive!! most tutorials would need 16 minutes for this... uggggggh
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
Subscribing just for the upbeat music at a reasonable level in the background
Thanks for this!!! I really lovethe format of your videos, just keep it up! Day 2 of asking for a simpler Inventory system btw
Sure, how about a weapon wheel as well?
@@jondevtutorials4787 yes
"It is legally required to like the video, you dont wanna end up like this guy" 😂😂😂😂😂😂
Really good tutorial, thanks for the help
If you don't subscribe after watching such an eloquent tutorial, pls don't make games.
Easy to follow, informative and fucking funny had to subscribe!
This is so good for my game thanks
very useful! gonna save it for next project XD
Thanks my good sir
this reminds me of my time in uni.
they didn't bother to explain anything either.
Love it
Thank you so much.
cool stuff dude
Awesome, this helped me so damn much. Appreciate it, have a like as by contract ;P
GEENIUSSS!!!!
It works :)
Thanks sooo much
tnx mate
thanks man
thank you
Please help, he just stops at the middle
Danke
How do I give logic to the randomness. Such that the agent may run away from player in a random zig-zag manner
Like👍
Hello there! Is it mandatory to bake both the surfaces from the navmeshSurface component and also from the navMeshAgent?
How can I make the NPC fly up and down with this? (By setting layers of baked navmash for instance)
Obligation fulfilled🤪
Where can I find the navmesh agent and what should I put in the boxes: "Agent, Range and Centre Point" ?
what do i set for centre point
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
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
Is there any way I could make so if the enemy detects the player it sets the player as the destination?
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.
Hello, thanks for this tutorial. But what do you put in Centre Point ? Thanks
Just create an empty gameobject and use that. Position the empty gameobject on the floor of the navmesh.
Does anyone have any ideas on how to play walking animations for humanoid npcs
what do i do with the navmesh? i somehow cant get it to work
How could I implement this in 2D?
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
Can you make something like this but with a car ?
My agent get stuck at destination point. He wont finish the path
Question does anyone know how to make it work on VRCHAT?
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?
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
@@miquelsunyerroda9638 ok thx it works now
I'm definitely doing something wrong. I applied the script to a capsule but nothings happening
Did you bake a navmesh?
@@jondevtutorials4787 Yes, the floor was blue
Hello brother can we reduce the stoping time between the points?
Hello brother,
Play with your navmeshagent settings in the inspector. Try increasing acceleration, disabling autobreaking etc.
Best of luck
@@jondevtutorials4787 i will try and see
@@spai_wolf8561 Did it works? And what did you change ??
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
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)
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.
@@jondevtutorials4787 i managed to fix the problem... thank you very much
@@vladaslittleparadise4402 i`m having the same problem.. what did you change?
@@se5d nothing really... I just re-did it
@@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.
How can I make it work in a 2D game?
you use vector 4's - and then divide by two
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
I can’t read
Too lazy for waypoints it is.
Can this work for 2D?
Is there a way to visualize the Range that the MOnster have ?
Yes you can use Gizmos