Search Unity

  1. We are migrating the Unity Forums to Unity Discussions by the end of July. Read our announcement for more information and let us know if you have any questions.
    Dismiss Notice
  2. Dismiss Notice

Unity Animation Axis LookAt Slerp. Idle Animation not facing correctly

Discussion in 'Animation' started by diegomh7, May 31, 2017.

  1. diegomh7

    diegomh7

    Joined:
    Feb 14, 2016
    Posts:
    6
    Hi all...

    I have two characters on stage which have mixamo idle animation states for a fighter stance.

    I have placed the characters facing each other on a vuforia used defined target and used a Slerp rotation to make each character face each other. The problem I have is that as soon as the idle animation kicks in they both face about 45 degrees to the left. I have looked at the animation and can't see a rotation anywhere, so I'm thinking it may be the axis. I've added two screenshots below to demonstrate the problem.



    The left character has a white line between the feet showing that the gameobject is indeed facing the character on the right. When I look at the animator, the idle animation is looping correctly and if I move the character around the look rotation works but is still offset.

    I copied the mixamo animation to remove the read only attribute and see if I could fix it. I just can't see any rotation anywhere. I also tried embedding the character in a parent transform and rotating the transform with no joy.

    I entered a play mode and looked at the animation panel. Something interesting happened then. When I moved the scrubber one frame, the character jumped into the correct facing position.

    A picture below shows this.



    Suddenly the positioning was spot on, even though it stopped the animation playing whilst in the play mode.

    This made me think its not an axis issue with the model but code. I have a script attached to each player. Here's the update method.



    void Update(){

    if (!anim.GetCurrentAnimatorStateInfo(0).IsName("knocked_out")){
    transform.position = new Vector3(transform.position.x,0,transform.position.z);
    }

    if (anim.GetCurrentAnimatorStateInfo(0).IsName("fight_idle")){
    Vector3 direction = enemy.position - this.transform.position;
    direction.y = 0;
    this.transform.rotation = Quaternion.Slerp(this.transform.rotation, Quaternion.LookRotation(direction),0.1f);
    }
    if(Input.GetKeyUp(KeyCode.Space)){
    reaction();
    }
    if(Input.GetKeyUp(KeyCode.K)){
    flyingKick();
    }

    if(DefaultTrackableEventHandler.lostFound == true){
    anim.SetBool("started", true);
    GameObject theClone = GameObject.Find("UserDefinedTarget-1/Holder");
    theClone.transform.localPosition = new Vector3(0,0,0);
    }

    }




    It's sending me a little crazy and I'm at the point of breaking it more, I've even tried a different idle animation and had the same result so something has to be off.

    This is the fighters original transform position before the play mode is entered if that sheds any light on the problem.



    And here is the animation controller.




    I've tried adding a child transform to each character and targeting that but when the characters are close they don't face each other as the child needs to be offset on the Z axis.

    I've seen similar questions online but most refer to looking at the camera or getting an object to look at the character all the time. I need both these guys to face each other. They do, without animation. I've tried playing with root animation on and off with no joy either.

    Help appreciated.
     
  2. diegomh7

    diegomh7

    Joined:
    Feb 14, 2016
    Posts:
    6
    After hours and hours, I found the problem. I had to go into the animator and double click the problematic animation. Using the inspector on the right hand side I changed the dropdown root transformation and resolved the issue of the axis pivot.



    Seen as nobody answered maybe this is something problematic for a few people so hopefully I will save someone else the pain of figuring out.
     
  3. P47HF1ND3R

    P47HF1ND3R

    Joined:
    Feb 5, 2023
    Posts:
    2
    Saved my life, thank you so much but i think what also worked is you just play around with the offset and I think that fixed my issue too