Hello, I’m making a top down 2d game where I need to make an object (a zombie that the player resurrects) starts following the player as soon as it instantiated but I also want to keep him at a distance. I’ve managed to do this with the following script but it doesn’t look natural at all, the zombie looks like a force field around the player instead of it following him.
This is the script I’ve been using :
private GameObject player;
public float moveSpeed;
public float distance;
// Use this for initialization
void Start () {
player = GameObject.FindGameObjectWithTag("Player");
}
// Update is called once per frame
void Update () {
transform.position = (transform.position - player.transform.position).normalized * distance + player.transform.position ;
}