- Home /
How can i make my soldier to patrol over the space station in random ?
I mean i want to bake all the places in the space station and make the soldier to move automatic around the spaceship to random places.
What i did so far is places the soldier at a start point. Added a camera as child to the soldier. Added a nav mesh agent component to the soldier.
Attached a script to the soldier: It's not my script. I don't want the soldier for now to chase only to walk randomly around the space station.
I didn't change any of the setting on the Nav Mesh Agent component in the inspector and i didn't
Should i change anything in the nav mesh agent component and if so what ?
How do select or set what areas to bake so the character will know to walk to this areas or if i want to select all the areas ?
How do i tell the character when to turn right or left in case there is a wall ? Could be also random to turn left or right. Depending if there is left and right ways or maybe there is also straight way so that's 3 possible ways to move to.
clicked the Bake button yet.
I didn't write yet the script:
using UnityEngine;
using System.Collections;
public class SoldiersPatrol : MonoBehaviour
{
}
I noticed now that when i click the Navigation window and then Object and All i see a message: Select a MeshRenderer or a Terrain from the scene. But i don't have a terrain the space station is a object. And mesh renderers there are many a lot. So what do i do in this case ? I can't click the Bake button it does nothing.
I also saw in the unity tutorial that i should set a target where the agent the character should go to. But i want the character to walk random aorund the space station. Do i need then to add random targets around the station ?
Answer by Yuvii · Oct 10, 2017 at 08:56 AM
Hey,
With a quick search on google i found these links; I think it's pretty much what you're looking for, and it looks like they explain it all pretty well :)
https://docs.unity3d.com/Manual/nav-AgentPatrol.html
https://shbai.wordpress.com/2015/08/28/how-to-make-an-ai-navmesh-agent-patrol-in-unity/
https://www.youtube.com/watch?v=Puqupldb4yc
To bake an object for the navmesh, be sure that it has a collider and is static (any object, not only terrain) and the objects you want to bake are selected. Then click on Bake button in the bottom right corner.
If it says 'Select a MeshRenderer or a Terrain from the scene', well it's well explained that you don't have any object selected. In your case, your station is an object that you can see, SO it has a meshRenderer component, so just select the object on the scene.
For the random path, you should try to add some points in random position of your station, then your patroller will target one of these points randomly.
Your answer
Follow this Question
Related Questions
Unity Navmesh agent patrol and chase player script issues. 0 Answers
Make NavMesh move to random positions 1 Answer
Is it right to turn false both navmeshagent updateRotation and updatePosition properties ? 0 Answers
How can i prevent from mouse to collide with thirdpersoncontroller ? 0 Answers
How can i change the walls height and keep the size for example 100x100 but height 0.1 ? 1 Answer