i need some help i made this AI but the enemy goes through walls this is my code (please write down the code so i can just copy it):
using UnityEngine;
using System.Collections;
public class EneMyAI : MonoBehaviour {
public Transform target;
public int moveSpeed;
public int rotationSpeed;
public int maxdistance;
private Transform myTransform;
void Awake(){
myTransform = transform;
}
void Start () {
GameObject go = GameObject.FindGameObjectWithTag("Player");
target = go.transform;
maxdistance = 2;
}
void Update () {
Debug.DrawLine(target.position, myTransform.position, Color.red);
myTransform.rotation = Quaternion.Slerp(myTransform.rotation, Quaternion.LookRotation(target.position - myTransform.position), rotationSpeed * Time.deltaTime);
if(Vector3.Distance(target.position, myTransform.position) > maxdistance){
myTransform.position += myTransform.forward * moveSpeed * Time.deltaTime;
}
}
}
↧