I have faux gravity working for the player character and AI controlled characters, but I’m having Issues with AI. When the AI characters reach the equator they stop following the player, and run to the opposite side of the planet.
using UnityEngine;
using System.Collections;
public class EnemyAISphere : MonoBehaviour {
public Transform target;
public int moveSpeed;
public int rotationSpeed;
//max distance from target before attack
public int maxDistance;
private Transform myTransform;
void Awake() {
myTransform = transform;
}
// Use this for initialization
void Start () {
GameObject go = GameObject.FindGameObjectWithTag("Player");
target = go.transform;
maxDistance = 2;
}
// Update is called once per frame
void Update () {
//Draws Targeting Line for Debugging
Debug.DrawLine(target.position, myTransform.position, Color.green);
if(maxDistance < 2)
animation.CrossFade("idle");
else
animation.CrossFade("idle");
//NPC Look atTarget
myTransform.rotation = Quaternion.Slerp(myTransform.rotation, Quaternion.LookRotation(target.position - myTransform.position), rotationSpeed * Time.deltaTime);
//NPC will move is its distance from target is greater then the max distance. Sets NPC range
if(Vector3.Distance(target.position, myTransform.position) > maxDistance){
//NPC Move Towards Targeting
myTransform.position += myTransform.forward * moveSpeed * Time.deltaTime;
animation.CrossFade("walk");
}
}
}
Thanks