I decided to try exporting a Blender model in an FBX with animations to Unity. There are two animations, open and close for the top door of this model. Here's the thing - it seems my model likes to jump into the origin of BOTH animations when the model started, ie. if I import the model and the door is open, and I decide to trigger to CLOSE it, it will close properly - but then, when I try to OPEN it, it decides it needs to stay at the SAME origin as the closing door animation first, THEN it opens - basically causing the door to move too far OUTSIDE of the model.
I've also made a point to try leaning on ONE animation in the Mecanim animator control - but it seems while it gets back to the correct place for the door when moving in the opposite direction, it doesn't do it at the same speed, but does so erratically. Finally, when I try to have one door animation transition to the SAME door animation with the opposite speed (ie. door close to door close, one with speed of 1 and one with -1) it still jumps erratically.
Here's the last Mecanim animator setup I attempted:
This was the approaching of trying to use the same animation in the other state, but negative speed instead of positive. It doesn't work like you would expect.
I'm using state triggers to transition between these states in the code below:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Playables;
public class TriggerAnimation : MonoBehaviour {
public Transform cockPit;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if (Input.GetKeyDown("t"))
{
//AnimationPlayableUtilities.PlayClip("CockPit_ExtDoor|Open");
Debug.Log("I'm being pressed");
//GetComponent<Animator>().SetTrigger("ExtDoorOpen");
GetComponent<Animator>().SetTrigger("IntDoorOpen");
//GetComponent<Animator>().SetTrigger("CockPit_Door|Open");
}
if (Input.GetKeyDown("u"))
{
//PlayableGraph graph = new PlayableGraph();
//AnimationPlayableUtilities.PlayAnimatorController(GetComponent<Animator>(), GetComponent<RuntimeAnimatorController>(), out graph);
Debug.Log("I'm being pressed");
//GetComponent<Animator>().SetTrigger("ExtDoorClose");
GetComponent<Animator>().SetTrigger("IntDoorClose");
//GetComponent<Animator>().SetTrigger("CockPit_Door|Close");
}
if (Input.GetKeyDown("x"))
{
GetComponent<Animation>().Play("CockPit_IntDoor|Open");
}
if (Input.GetKeyDown("z"))
{
GetComponent<Animation>().Play("CockPit_IntDoor|Close");
}
}
}
Can someone let me know if there's a better way to approach this and how? I've tried jumping between several articles on this, including a demo tutorial on Mecanim for Unity on their website - no dice...