# How can i make my soldier to patrol over the space stationin 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 placing 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. – user1196715 Oct 9 '17 at 23:59
• 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 ? – user1196715 Oct 10 '17 at 0:01

I show you with like a psudo code:

system.random rnd = new system.random();
GameObject[]  points;
// assume you have 5 possible points that you can go
int moveIndex;
void update()
{

transform.position= vector3.movetowards(transform.position,points[moveIndex].transform.position,speed);
if(vector3.distance(transform.position,points[moveIndex].transform.position)<1)
{
moveIndex= rnd.next(1,6);
}

}