- Home /
How to make an enemy backpedal?
Hello, I am coding an AI to move towards the player and then stop at a certain distance, which I have done, but the player can still move directly on top of the enemy. I don't want collision as i need the player to be able to pass through but I would like the enemy to back pedal to a minimum distance and a slightly slower movement speed>
So far I have this, but can figure ot how to make them walk back to the minimum distance.
if(Vector3.Distance(target.position, myTransform.position) > maxDistance){
//Move towards target
myTransform.position +=(target.position - myTransform.position).normalized * solMoveSpeed * Time.deltaTime;
}
if(Vector3.Distance(target.position, myTransform.position) < minDistance){
//Backpedal from target
}
Answer by robertbu · Jan 10, 2014 at 04:14 PM
Just reverse your parameters when calculating the movement direction:
myTransform.position += (myTransform.position - target.position).normalized * solMoveSpeed * Time.deltaTime;
Your answer
Follow this Question
Related Questions
How to make smooth jump? 1 Answer
AI controller script, Enemy movement issues 0 Answers
Small Project, tutorials/help needed 0 Answers
Keeping Character From Walking Through Walls 1 Answer
Problems In Flocking Algorithm 1 Answer