# Enemy follow player on planet

Hello everyone, I’m working on game like Mario Galaxy. I have a problem with “enemy follow script”.
The script works fine until enemy reaches equator of planet and then starts spinning crazy.

Here is my Enemy Follow Script:

``````var lookPos = GetComponent<AiBehavior>().targetNode.transform.position - transform.position;
lookPos.y = 0;
var rotation = Quaternion.LookRotation(lookPos);
transform.rotation = Quaternion.Slerp(transform.rotation, rotation, Time.deltaTime * 5f);

GetComponent<Rigidbody>().MovePosition(GetComponent<Rigidbody>().position +   transform.TransformDirection(moveAmount) * Time.fixedDeltaTime);
``````

Scripts for Gravity:

``````GravityAttractor

public float gravity = -10;

public void Attract(Transform body)
{
Vector3 targetDirection = (body.position - transform.position).normalized;
Vector3 bodyUp = body.up;

body.rotation = Quaternion.FromToRotation(bodyUp, targetDirection) * body.rotation;

}

Gravity body

public FauxGravityAttractor attractor;
private void PlanetGravityCalculation()
{
attractor = GameObject.FindGameObjectWithTag("Attractor").GetComponent<FauxGravityAttractor>();
GetComponent<Rigidbody>().constraints = RigidbodyConstraints.FreezeRotation;
GetComponent<Rigidbody>().useGravity = false;
}
private void PlanetGravityProces()
{
attractor.Attract(transform);
}
``````

Any Ideas :)?

Well, you could write a better script… or you could flub it so your enemy is never on the equator, such as its start coordinate being an odd number and its coordinates increasing by 2 so it never touches the equator – or if its location is on the equator it increases by +1 in the current movement vector.