Answer the question
In order to leave comments, you need to log in
How to make enemy AI with obstacle avoidance?
I'm trying to make a 3D maze over the net, but I can't write the code to make the enemy go to the nearest player and pass obstacles
Here is the script:
using UnityEngine;
using System.Collections;
public class Enemy : MonoBehaviour {
public Transform player;
public float move_speed;
public float rotation_speed;
public Transform enemy;
void Update()
{
var look_dir = player.position - enemy.position;
look_dir.y = 0;
enemy.rotation = Quaternion.Slerp(enemy.rotation,Quaternion.LookRotation(look_dir),rotation_speed*Time.deltaTime);
enemy.position += enemy.forward * move_speed * Time.deltaTime;
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question