- Home /
2 Animations At once
I want to play 2 animations at once so the arms play the melee attacking animation while the body plays the animation it was normally doing (standing or running etc.). I think i have to use animation.Blend but i havent a clue how it works. Here is my script:
public GameObject player;
public float turnSpeed = 1.0f;
public float time = 1f;
public float speed = 1f;
public GameObject Leg;
// Use this for initialization
void Start ()
{
animation.Play("Standing");
animation["Jump"].speed = 1.15f;
animation["Falling"].speed = 0.42f;
Screen.lockCursor = true;
}
// Update is called once per frame
void Update ()
{
if(Input.GetMouseButtonDown(0))
{
}
player.GetComponent<CharacterController>().enabled = true;
{
if (animation["Jump"].enabled == false)
{
}
}
if(Input.GetKeyDown(KeyCode.Escape))
{
player.GetComponent<MouseLook>().enabled = false;
maincamera.GetComponent<MouseLook>().enabled = false;
}
if(Input.GetMouseButtonDown(0))
{
Screen.lockCursor = true;
player.GetComponent<MouseLook>().enabled = true;
maincamera.GetComponent<MouseLook>().enabled = true;
}
if((Input.GetKeyDown(KeyCode.W))&&(Input.GetKeyDown(KeyCode.D)))
{
transform.Rotate(0,45,0);
}
if((Input.GetKeyUp(KeyCode.W))&&(Input.GetKeyUp(KeyCode.D)))
{
transform.Rotate(0,225,0);
}
if(Input.GetKeyDown(KeyCode.W))
{
animation.CrossFade("Run");
}
if(Input.GetKeyUp(KeyCode.W))
{
animation.CrossFade("Standing");
}
if(Input.GetKeyDown(KeyCode.D))
{
animation.CrossFade("Run");
transform.Rotate(0,90,0);
}
if(Input.GetKeyUp(KeyCode.D))
{
animation.CrossFade("Standing");
}
if(Input.GetKeyDown(KeyCode.A))
{
animation.CrossFade("Run");
transform.Rotate(0,-90,0);
}
if(Input.GetKeyUp(KeyCode.A))
{
animation.CrossFade("Standing");
}
if(Input.GetKeyDown(KeyCode.S))
{
animation.CrossFade("Run");
transform.Rotate(0,180,0);
}
if(Input.GetKeyUp(KeyCode.S))
{
animation.CrossFade("Standing");
}
if(Input.GetKeyDown(KeyCode.Space))
{
animation.CrossFade("Jump");
}
}
}
I have been playing around with $$anonymous$$ecanim and animations over the last day or so and found that wrapping up your blend states into conditionals help with controlling animation transitions as you can then layer your actions separately. After this you can make a blendState in your new layer and by double clicking it, you can reach a new window in inspector panel that allows you to add as many animations as you like and then with a handy window allows you to specify the transition time and easing from one to another. Importantly: you should add a parameter(like "Speed") in the parameters box in the Animator window, this is what you will use as your defining value to check against to tell where in the transition your animations should be playing. (the principle applies if you wanted to play two animation at the same time and may not even need you to specify a parameter in Animator window as you are not transitioning as such, but rather piling on two anims to play simultaneously)
Your answer
Follow this Question
Related Questions
please help with my melee attack animation 1 Answer
Animations Combo 0 Answers
Melee attacking, using force and health values 1 Answer
Not identifying the collider? 2 Answers