Sort of like random paths around them.. I want them to be walking within somewhere near them so they dont walk all over the map just little steps yunno...
THANK YOU so much for future help hhaha
using UnityEngine;
using System.Collections;
public class EnemyAI : MonoBehaviour {
public Transform target;
public int moveSpeed;
public int rotationSpeed;
public float width = 5;
float rx = Random.Range(-1,1);
float rz = Random.Range(-1,1);
private Transform myTransform;
void Awake() {
myTransform = transform;
}
// Use this for initialization
void Start () {
GameObject go = GameObject.FindGameObjectWithTag("Player");
target = go.transform;
}
// Update is called once per frame
void Update () {
float distance = Vector3.Distance(target.transform.position, transform.position);
Debug.Log(distance);
if(distance < 10 && distance > 2) {
Debug.DrawLine(target.position, myTransform.position, Color.red);
//look at target/rotate
myTransform.rotation = Quaternion.Slerp(myTransform.rotation, Quaternion.LookRotation(target.position - myTransform.position), rotationSpeed * Time.deltaTime);
//move towards target
myTransform.position += myTransform.forward * moveSpeed * Time.deltaTime;
animation.Play("walk");
}
if(distance < 2) {
animation.Play("attack");
}
if(distance > 10) {
animation.Play("idle");
}
}
}
↧