Making an enemy follow the player if the players transform doesn't change.

I’ve got an enemy coded for a project I’m working on. The enemy is supposed to look at and follow the player once they get within a certain distance. The problem is, recently we’ve started using a new program to move the player throughout the level. The issue is, this program moves the player without actually changing the transform component of the object and I don’t know how to alter my code to deal with that.

Here’s the target assignment, the follow method and the lines that assign the distance from the player as well as the calls for the LookAt and Follow methods.

void Start (){

	Target = GameObject.FindGameObjectWithTag ("Player").transform;

void Update () {

	Distance = Vector3.Distance (Target.position + Target.transform.forward, transform.position);
	if (Distance < LookAtDistance)
	if (Distance > MinDistance && Distance <= MaxDistance && parenting == false)
		follow ();

void follow(){
	transform.Translate(Vector3.forward * MoveSpeed * Time.deltaTime);

Any help would be greatly appreciated.


Finally got a chance to get back to this. I’ve done some testing with everything and these are the results.

No matter what object I set as player, be it the actual player object, the main player group object which everything is parented to (player itself, camaera, one additional object) (don’t have a changing transform), or the Main Camera (Actual does have a changing transorm) the enemy does not follow as it should. Depending on which object I tag as player though the enemy will transform in a different direction, just not toward the player. There had been a couple times when the enemy would go below the ground or actually up in the air.

There was one time when I was able to get the enemy to go towards the player and that was when I took it out of the parenting groups and left it just as itself. The problem here though is, the camera is what is moved through the level with the program and therefore the player doesn’t move if it isn’t parented to it.

It seems likely that some kind of GameObject is at the location where your player is being represented. If so, it has a Transform you can use even if it’s a child (TransformPoint).