x


AI fleeing -

I'm trying to make a game object flee away. How can i create a fleeing AI?

more ▼

asked Nov 21 '10 at 09:45 PM

sam gravatar image

sam
48 20 23 28

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

The simplest method would be to compute the 'flee direction' as follows:

// Assumes object positions are not coincident or nearly coincident:
Vector3 fleeDirection = transform.position - objectToFleeFrom.transform.position;
fleeDirection.Normalize();

And then use the computed direction vector to move the object using whatever method is appropriate (e.g. apply a force for a rigid body, incorporate into the movement vector for a character controller, etc.).

more ▼

answered Nov 21 '10 at 10:46 PM

Jesse Anders gravatar image

Jesse Anders
7.3k 7 17 48

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x956
x5

asked: Nov 21 '10 at 09:45 PM

Seen: 858 times

Last Updated: Nov 21 '10 at 09:45 PM