- Home /
I need help with Follow AI (C#)
So i am making a zombie survival game and i attached this script to the zombie. It is supposed to follow the object with tag "player", i also made a permimeter float named speed on animation controller. I have 2 animations. idle and walk. between them are thransactions. there are also 2 conditions. if speed is greater than 0.1 it will start walk animation and if less than 0.1 it will start idle animation. But for some reason it isnt working. Can you guys help me please?
SCRIPT:
using UnityEngine; using System.Collections;
public class EnemyController : MonoBehaviour { NavMeshAgent nav; Transform player; Animator controller; // Use this for initialization void Awake () { nav = GetComponent (); player = GameObject.FindGameObjectWithTag ("Player").transform; controller = GetComponentInParent (); }
// Update is called once per frame
void Update () {
nav.SetDestination (player.position);
controller.SetFloat ("speed", Mathf.Abs(nav.velocity.x) + Mathf.Abs (nav.velocity.z));
}
}
Your answer
Follow this Question
Related Questions
Waypoint Arrow not pointing at tagged object ? 1 Answer
help me add animation and delay to my waypoint script plizz 0 Answers
Hit any gameobject, animation will play? 1 Answer
Help With Animation 1 Answer
Waypoint/Animation help 2 Answers