So I created a script where my dog follows me....And the problem is animations...I have animation component on my dog game object and when I move inside the non-following range he plays Idle animation... but when i go outside the range he starts to follow me but animation is not working... Its like he is tiggling left and right for a few inches constantly Code (CSharp): using UnityEngine; using System.Collections; public class pet : MonoBehaviour { public float speed; public float range; public Transform player; public CharacterController controller; public Animation move; public Animation Idle; private void Start() { move = GetComponent<Animation>(); Idle = GetComponent<Animation>(); } void Update() { if (!inRange()) { chase(); } else { } } bool inRange() { Idle.Play("idleLookAround"); return Vector3.Distance(transform.position, player.position) < range; } void chase() { Idle.Stop("idleLookAround"); move.Play("walk"); transform.LookAt(player.position); controller.SimpleMove(transform.forward * speed); } }
Your inRange() function also contains a Play() call. I don't think you want line 33 there. More likely you want the contents of line 33 on line 28.
Thanks for that... the thing was also with AI movement speed...speed was equal sort of...but now when he is slower than me when he stops transition from walk to idle animation is not there...I know transitions with animator controller but in scripting not... any tips?