Problems with basic enemyAI on sphereical world
I have a spherical world using basic faux gravity and the player works perfectely but you can't NavMesh bake a 3d object like that so I made my own very bad script. I left out the y in the vector because otherwise the enmy would try to go into the ground at certain angles. But this causes strange behaviours: the enemy goes to the wrong spot where the z and x coördinates are the same but the y negative and when the enmy does reach destination it circles the player and then shoots of to the other coördinate.
Script:
public Transform player;
private Rigidbody rb;
public Vector3 moveDirection;
public float speed = 20;
// Use this for initialization
void Start ()
{
player = GameObject.FindGameObjectWithTag("Player").transform;
rb = GetComponent<Rigidbody>();
}
// Update is called once per frame
void Update ()
{
moveDirection = new Vector3(player.transform.position.x - rb.transform.position.x, 0, player.transform.position.z - rb.transform.position.z).normalized;
}
private void FixedUpdate()
{
rb.MovePosition(rb.position + transform.TransformDirection(moveDirection) * speed * Time.deltaTime);
}
Your answer
Follow this Question
Related Questions
Help with enemy AI 1 Answer
I have rotation problem, I look forward to helping. 0 Answers
AI stops following player. 1 Answer
Enemy AI Issues!!?! 2 Answers
How can I treat the surface of a sphere as a 2 dimensional surface? 0 Answers