- Home /
AI fleeing -
I'm trying to make a game object flee away. How can i create a fleeing AI?
Comment
Answer by Jesse Anders · Nov 21, 2010 at 10:46 PM
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.).
Your answer
![](https://koobas.hobune.stream/wayback/20220613083919im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
AI fleeing from multiple enemies 0 Answers
make an AI Flee 0 Answers
Help With Waypoints script 1 Answer
Fleeing AI...... 1 Answer