Search Unity

[SOLVED]Play animation of child characters

Discussion in 'Animation' started by Bilobog, Dec 7, 2016.

  1. Bilobog

    Bilobog

    Joined:
    Oct 12, 2016
    Posts:
    20
    Hello again.

    I'm making a little strategy game (not for commercial use) and want a group of solders (Ethan model) to walk in formation.
    So I create an empty GameObject, set a formation of solders there and attach this script to that Game Object:

    using UnityEngine;
    using System.Collections;

    public class ClickToMove2 : MonoBehaviour {

    private Transform myTransform;
    private Vector3 destinationPosition;
    private float destinationDistance;

    public float moveSpeed = 5.0f;
    public float rotateSpeed = 90f;
    public float stopDistance = 0.1f;

    private Quaternion targetRotation;

    void Start ()
    {
    myTransform = transform;
    destinationPosition = myTransform.position;
    }

    void Update ()
    {
    if (Input.GetMouseButtonDown(1)&& GUIUtility.hotControl == 0)
    {
    Plane playerPlane = new Plane(Vector3.up, myTransform.position);
    Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
    float hitdist = 0.0f;
    if (playerPlane.Raycast(ray, out hitdist))
    {
    destinationPosition = ray.GetPoint(hitdist);
    }
    }
    Vector3 destDir = destinationPosition - myTransform.position;
    destDir.y = 0;
    destinationDistance = destDir.magnitude;
    if (destinationDistance >= stopDistance)
    {
    targetRotation = Quaternion.LookRotation(destDir);
    myTransform.rotation = Quaternion.RotateTowards(myTransform.rotation, targetRotation, rotateSpeed * Time.deltaTime);
    myTransform.Translate(Vector3.forward * 0.2f * Time.deltaTime * moveSpeed);
    }
    }
    }

    It's move the whole formation just fine with rotations and else(Thank to the author of script, which name I don't know). But solders, while GO is move to destination point, play only "HumanoidIdle" animation.
    How to make my child character to play certain animations(walk or idle, or else), when parent is moving/rotating by this script?

    I'll be thankful for any help.
    Best Regards.