- Home /
How do I root for movement and rotation on my enemy ai
I am having a problem rooting my enemy ai in my scene, What going is I got an animation attach to my enemy and what is happening it every time I kill the enemy ai the animation takes over the coordinates and moves the object back to 0,0,0 . I created a empty gameobject drag the child into the empty gameobject. I know need to make some changes in the inspector . I have a pic here to show where I am at .
You should use 'NAVIGATION' concept to move enemy ai. also you didnt attach any 'Animator Controller' to your Animator. Follow below tutorial.. and get back to me.... if you have any doubts unity3dworkouts.blogspot.in/2015/07/enemy-agent-waypoint-petrol-attack.html
Answer by satyagames · Jul 14, 2016 at 09:36 AM
You should attach Patrol.cs to Enemy
Meanwhile you should create way points manually or by using WaypointCircuit.cs script
Below i attached screenshots of InspectorView. Based on that you can arrange your enemy characters.
//Patrol.cs using UnityEngine; using System.Collections;
public class Patrol : MonoBehaviour {
public Transform[] points; private int destPoint = 0; private NavMeshAgent agent; //public NavMeshAgent agent2; Animator m_Animator; public Transform target; void Start () { agent = GetComponent<NavMeshAgent>(); //agent.updatePosition = false; // Disabling auto-braking allows for continuous movement // between points (ie, the agent doesn't slow down as it // approaches a destination point). agent.autoBraking = false; m_Animator = GetComponent<Animator>(); GotoNextPoint(); } void GotoNextPoint() { // Returns if no points have been set up if (points.Length == 0) return; // Set the agent to go to the currently selected destination. agent.destination = points[destPoint].position; // Choose the next point in the array as the destination, // cycling to the start if necessary. destPoint = (destPoint + 1) % points.Length; } void Update () { // Choose the next destination point when the agent gets // close to the current one. if (agent.remainingDistance < 0.5f) GotoNextPoint(); if (hero.erun == true) { m_Animator.SetBool ("run", true); agent.speed = 3; transform.LookAt(target); } else { m_Animator.SetBool ("run", false); agent.speed = 2; } if (hero.eattack == true) { m_Animator.SetBool ("attack", true); agent.speed = 0; //agent.updatePosition = false; //transform.LookAt(Vector3.zero); } else { m_Animator.SetBool ("attack", false); //agent.speed = 2; //agent.updatePosition = true; } } }
Enemy Character Inspector Screenshot :-
I have legacy animation. I just trying to be to kill the enemy when its near the player and play the death animation on time. I can't use animator controller because unity won't allow me because I have legacy animations. Why do I need enemy patrol ? The problem is that the death animation is not playing when I kill the enemy ai. The enemy ai just play the move animation and it vanish . I am trying to fix that problem.