R
R
Reaper Crow2020-05-19 20:55:48
Unity
Reaper Crow, 2020-05-19 20:55:48

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

2 answer(s)
F
freeExec, 2020-05-19
@freeExec

Use NavMeshLuke.

K
Kot Kotov, 2020-05-20
@kot123123

Try to go on a spree if you don’t understand in text format, then go to YouTube

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question