Quantcast
Channel: Questions in topic: "enemy"
Viewing all articles
Browse latest Browse all 1488

Help AI going through walls

$
0
0
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; } } }

Viewing all articles
Browse latest Browse all 1488

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>