banner



How To String To Animations Together In Unity

How to run two animations at one time? This is one of the most common trouble in the animations field. Permit's see how Unity can aid u.s. to solve this problem.

Permit's assume this situations: Yous have a 2d character that has a run animation and a run-attack blitheness, and you want to brand the character exist able to run and attack at the same time. At present the simple solution is to play the run animation when when player first to run, and switch to the run-attack animation when the actor press the assail push button, the trouble is that the transition between the run and the run-attack animation is non a shine transition. The problem tin can exist solved with ii solutions:

Animation Blend

The piece of cake 1 is to employ the Animation.Alloy method provided by unity:

public void Alloy(string animation, bladder targetWeight = i.0F, float fadeLength = 0.3F);

What does this method exercise?

It Blends the blitheness named animation towards targetWeight over the next time seconds.  Basically is a shine mode to go from ane animation to another one.

Run two animation at in one case.

Simply what if y'all have two very circuitous animations which are very difficult to synchronize? the best solution is split the 2 animations into three animations:

  1. 1 is the animation used to breathing the legs.
  2. Another is the animation used to animate the trunk.
  3. Another is the animation used to breathing the trunk while the attack is occurring

Once we have the animations, when the histrion press the push button to attack while the character is running, only the the torso animation will be switched, and to brand the transition even more than smoothen, nosotros'll use the Animation.Alloy method to alter from the run animation of the body to the run-attack animation of the torso.

Permit see how to use Unity to achieve the result that we desire:
First affair to do Is to create the Avatar to use. Let'south create a Hero graphic symbol with a rigidbody attached:

Unity add player

Has you tin can run into, our hero has i child gameObject named Body where we'll employ to attach the animations of the body, recall to attach a sprite rendere to the body if your animation is sprite based:

Adding sprite renderer

Now Import your animations sheet:

3

As you can come across, we have iii blitheness, one for the legs and 2 for the trunk..

Create the animations:

At present allow's add the animations to our character:

Select the legs and drag the frames into the player gameobject to automatically create an animation clip:

Create animation unity

Once washed, an blitheness controller along with an blitheness clip volition take been created:

Animator Unity

Now create the animations for the body, open the animation windows –> create new prune and select the body gameobject sprite rendere component:

Aniamtion clip add

Now add the animations frame:

7

Do the aforementioned thing for all the animations that needs to exist played on the upper office of the character:

Setting the animator:

At present open up the animator windows and create 2 states: Idle and run and a trigger that will switch from the Idle to the run land:

8

If we trigger the Playr_run condition, our animation volition get from the Idel state to the Run state, just this will only evidence the lower part of the animation, now nosotros have to add another Layer to our animator, the new layer volition allow us to add together another blitheness that will run simultaneously with the legs animation.
Go to Layer nether the animator window and click on the plus button to add together a new layer:

9

Click on the gears icon and set up is every bit shown in the following picture:

Setting layer animation unity

  1. The weight is the priority of the animations A higher layer number has a higher priority.
  2. The sync property will create an re-create of our first layer of the animator but with the advantages that on this layer, we can cull to run different animation. Go to the run animation on the layer that nosotros've just created and set the animation prune of the blitheness to the one relative to the upper part of the body:

set animation clip in aniamator

We take simply create a animator with ii layers that volition practice exactly the same, only on one layer we'll run the legs animation, and on the other the body blitheness.

Now the just thing that you have to practice, is to trigger the animations in code:

Run animation in code

Here I gave you the idea of how to run 2 animations at once.
This base example can exist hands expandable to run unlike animations or fifty-fifty more than then 2 animations at once.

Source: http://gamedevelopertips.com/unity-run-2-animations/

Posted by: campbelltorcer.blogspot.com

0 Response to "How To String To Animations Together In Unity"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel