Random Target/AI

Hi I’m working on a mordern day game, I bought the pro version to create some sort of AI for my pedestrians. My question is the following. Would it be possible for me to put multiple empty game objects across my city and for them to randomly select one as their target and then when they get there to choose an other so that they constently change target ? Or maby there is a easyer way ?

Thx in advance.

Sure, as simple as a pie.

public class MyAI : AIPath (or if you are using the beta, I recommend RichAI)
public Transform[] targets;

public void Start () {

public override void OnTargetReached () {

public void PickRandomTarget() {
//To get a random target
target = targets[Random.Range(0,targets.Length);

I haven’t tested the code, but something similar to that should work.

In the PickRandomTarger, could I say get object with tag (destination) as a target ?

I whant to make sure the target isint inside a building or a obstacle.

Well, I just added an array there, you can do whatever you like.
Transform pick = null; int tested = 0; for (int i=0;i<targets.Length;i++) { tested++; if (targets[i].gameObject.tag == "Whatever" && Random.value <= 1.0f/tested) { pick = targets[i]; } }
The above will pick a random transform with the tag “Whatever” with uniform probability from an array.

Ok thx il check this out when I get in the office

Thx, I found an other way to do it that suited best how we saw it. Just tell me what you think.

private GameObject[] targets; private Vector3 targetPosition

public void Start () {

	targets = GameObject.FindGameObjectsWithTag ("Destination");
	targetPosition = targets[Random.Range(0, 5)].transform.position;
	seeker = GetComponent<Seeker>();
	controller = GetComponent<CharacterController>();
	//Start a new path to the targetPosition, return the result to the OnPathComplete function
	seeker.StartPath (transform.position,targetPosition, OnPathComplete);</blockquote>