I’ve added the Unity-Chan to the AiPath to have its own animation, but I’m having a problem when Unity-chan reached the target, it will not stop and it will just run around and around. See video below
and here’s the my code for the Update method on AiPath Script
public virtual void Update () {
if (!canMove) { return; }
Vector3 dir = CalculateVelocity(GetFeetPosition());
//Rotate towards targetDirection (filled in by CalculateVelocity)
RotateTowards(targetDirection);
if (controller != null) {
float v = 0.5f;
anim.SetFloat("Speed", v);
anim.speed = animSpeed;
currentBaseState = anim.GetCurrentAnimatorStateInfo(0);
rb.useGravity = true;
velocity = new Vector3(0, 0, v);
velocity = transform.TransformDirection(velocity);
if (v > 0.1) {
velocity *= forwardSpeed;
}
transform.localPosition += velocity * Time.fixedDeltaTime;
} else if (rigid != null) {
rb.AddForce(dir);
} else {
tr.Translate(dir*Time.deltaTime, Space.World);
}
}