- Home /
How to make AI "roam around" convincingly on a navmesh?
So im making a zombie game and i need them to roam around convincingly before spotting player. I tried using this random turning method, but it just too random, it doesn't look convincing and quickly they all kinda start bumping in to walls. So does anyone have ideas for a better method? Or should i introduce intermediate directions like forward+left or even randomize the time turns should be taken? Or try some waypoint system?
void Update ()
{
turnTimer = turnTimer - Time.deltaTime;
Vector3 curLocation = gameObject.transform.position;
int randTurn = Random.Range (1, 4);
if (turnTimer < 0) {
if (randTurn == 1){
direction = Vector3.forward;
}
if (randTurn == 2){
direction = Vector3.back;
}
if (randTurn == 3){
direction = Vector3.left;
}
if (randTurn == 4){
direction = Vector3.right;
}
turnTimer = startTurnTimer;
}
//Debug.Log ("random vec" + randomTargetPos);
Vector3 randomTargetPos = curLocation + direction;
agent.SetDestination(randomTargetPos);
Answer by JovanD · Apr 09, 2014 at 09:40 PM
Nvm, this helped acheave what i wanted http://answers.unity3d.com/questions/475066/how-to-get-a-random-point-on-navmesh.html
Answer by rancid1 · Apr 08, 2014 at 09:27 PM
I'd recommend some kind of linked waypoint system. That is, any waypoint will know what other waypoints that it is connected to. Then make your moves from there.
Your answer
Follow this Question
Related Questions
NavMesh.SamplePosition returns point outside the NavMesh 0 Answers
Can you randomise a Navmesh agents rotation 1 Answer
Add randomness to Navmeshagent 0 Answers
Connecting two navmeshes without "Speedboost" 0 Answers
Agents taking wrong path 0 Answers