object to follow player at a distance

Hi all,

I’ve followed a heap of tutorials that should allow an object to follow my player and not collide with it but have had no luck. Does anyone have one that will work or know where I’m going wrong?

This is one tutorial I followed:

I’ve also used the below script, but have no idea how to stop the objects colliding with my player

using UnityEngine;
using System.Collections;

public class Enemy_AI : MonoBehaviour
{

Transform tr_Player;
float f_RotSpeed = 3.0f, f_MoveSpeed = 3.0f;

// Use this for initialization
void Start()
{

tr_Player = GameObject.FindGameObjectWithTag(“Player”).transform;

}

// Update is called once per frame
void Update()
{
/* Look at Player*/
transform.rotation = Quaternion.Slerp(transform.rotation
, Quaternion.LookRotation(tr_Player.position - transform.position)
, f_RotSpeed * Time.deltaTime);

/* Move at Player*/
transform.position += transform.forward * f_MoveSpeed * Time.deltaTime;
}
}

any help would be great!

Use Vector3.Distance

if(Vector3.Distance(transform.position,target.position) > 2)
{
     Walk();
}
1 Like