Hey,
I am trying to stop the AI enemy from bumping into my player and staying at a distance but unable to do so. can you please help me out??
I have colliders attached on both but trigger is off.
I am attaching the script which i am using for the enemy ai to chase my player
using UnityEngine;
public class KeepDistance : MonoBehaviour
{
public Transform player;
public float desiredDistance;
private void Update()
{
var offset = this.transform.position - player.position;
if (offset.sqrMagnitude < desiredDistance * desiredDistance)
this.transform.position = this.transform.position + offset.normalized * (desiredDistance - offset.magnitude);
}
}
This will keep an object at the desired distance to another object.