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
}