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: ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-bl9_bRZs0Gg.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
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.
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