i try to build and AI for my Game i follow the tutorial BurZerg Arcade and work Kind a the problem with the AI
the enemy cross over all the objects what mean if my Player hide behind a Wall the enemy cross over how i can make him to no go trough the Walls or objects.
this is the Code :
using UnityEngine;
using System.Collections;
public class enemy: MonoBehaviour {
public Transform target;
public int moveSpeed;
public int rotationSpeed;
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 () {
Debug.DrawLine(target.transform.position, myTransform.position,Color.red);
I believe it’s going to take a bit more code to achieve a decent working solution XD…
you may want first add some collider / trigger on your object environment, then maybe try with some simple avoidance code to make your enemy not cross your wall at first, there is plenty of example of that on the net I am sure, and using simple shape trigger it work generally not bad depending on your environment.
Or dive into pathfinding , there is a nice plugin for that for unity if I remember.
i having a problem the AI works well but how i came make to play the animations
this is the code :
//////////////variables used///////////////
var waypoint : Transform[ ];
var speed : float = 20;
private var currentWaypoint: int;
var loop : boolean = true;
var player : Transform;
var bullet: Transform;
animation.wrapMode = WrapMode.Loop;
///////////////////////////////////////
function Awake(){
waypoint[0] = transform;
}
function Update () {
if(currentWaypoint<waypoint.length){
var target : Vector3 = waypoint[currentWaypoint].position;
var moveDirection : Vector3 = target-transform.position;
var distFromPlayer : Vector3 = player.position-transform.position;
animation.CrossFade (“walk”);
function Shoot(){
var bullet = Instantiate(bullet,GameObject.Find(“shootpistion”).transform.position, Quaternion.identity);
animation.CrossFade (“run”);