Hi Guys, i would like to know how i can add a Animator Controller to a character using a Script. This is important as my characters will be generated during the runtime. I also have the problem that my persons do not look in the walking direction when using an animation, but they do without.
I really appreciate any help.
Here the code i am using for my second problem:
Animator animator = GetComponent<Animator>();
if (animator)
{
Vector3 moveDirection = waypoints[targetwaypoint] - transform.position;
moveDirection = 1f * moveDirection.normalized;
moveDirection.y -= 20f * Time.deltaTime;
transform.LookAt(moveDirection, Vector3.up);
controller.Move(moveDirection * Time.deltaTime);
if (Vector3.Distance(transform.position, waypoints[targetwaypoint]) <= waypointRadius)
{
targetwaypoint++;
if (targetwaypoint > waypoints.Length - 1)
{
targetwaypoint = 0; //looping around
}
}
}