- Home /
How to Play 2 Animations from the same Model at the same time?
Hi, i have imported a model of a flying ship with 2 (actually 3) animations, one to move the propellers and the other two to turn right or left the alerons, the animations are like this on the imported model:
Running propellers = frame 0 to frame 10
Turn left the alerons = frame 10 to frame 20 (turn and back to initial position)
Turn right the alerons = frame 20 to frame 30 (turn and back to initial position)
So, the model its imported OK into Unity with the 3 animations set, but i dont know how to play the running propellers animation and AT the same time play one of the other 2 animations for turning right or left while the propellers are still runnig.
The problem is that when the turn animation occurs, the propellers are still (between the frames 10 to 30 of the FBX model), i know there is a way to mask a specific part of a single model, but im not sure how to do it, anybody have a clue?, Thank You!
Answer by M-G-Production · Dec 04, 2014 at 04:35 AM
Hi Edyvargas!
First:
I really think you should create individuals animations for what you are trying to do here. When this will be done, set your Running propellers animation to Clampforever mode (wrapMode). So when it will be played, it will loop the last frame "forever" until you say anything else.
Then, with 2 individuals animations for each alerons (going right and going left) I really think you do more specifics things!
Oh and read about this: http://docs.unity3d.com/ScriptReference/Animation-wrapMode.html
Bests Math
Hi $$anonymous$$ath, Thank you for your answer,
Yes its more specific really, but i simplify it trying to make a simplier question, there is an animation for the alerons move to the right, other for the alerons back to the center for each one, other animations for the tail turn aleron and for the front tire and others, this doesnt involve the entire object movment, only the parts movement.
Ill check the things you answer now, thank you!
...for individual animations you mean each part of the model object animated into unity?, right now the model its separated into layers and each layer that has bones, has its own animation, but everything its animated in the same timeline of the imported model, separeted into Unity like this http://docs.unity3d.com/$$anonymous$$anual/Splittinganimations.html.
....Ops, i understand now, you mean dont use Animator Controller, and just set up animations with the Rig options of the model set to Legacy, and then add each animation to an Animation Component added to the model on the project....i do that, now im wondering how to play both animations on script cause the old way animation.play seems its not working on Unity 4.6 anymore...
Answer by zharik86 · Dec 04, 2014 at 08:49 AM
If your models have legasy animation and some bones, you can use layers and mixing animation. Example see below (write on CSharp):
//For example, your model have tree bones by names MainBone->CenterBone->Propeller
//Animation propellers only for bone "Propeller", animation is Loop
//Animation turns for bone "MainBone", animation is Once
void Start() {
//Find animation propellers and set layers more than other animation. Default is 0
this.animation["myAnimProp"].layer = 2
//Find bone for propeller and add mix. That play animation for propeller is only bone "Propeller"
this.animation["myAnimProp"].AddMixingTransform(this.transform.Find("MainBone/CenterBone/Propeller"));
}
void Update() {
//Play animation propellets
this.animation.CrossFade("MyAnimProp");
//Play animation turn of key down
if (Input.GetKeyDown(KeyCode.L)) {
this.animation.Play("MyAnimTurnLeft");
}
}
Attach this script at your model on Scene. I hope that it will help you.
Hi zharik86,
Thank you for you reply and code to achieve the both animations working with Legacy animation, i back my model to default animation mode cause found how to achieve the both animations working with layers as you say but throught the animation controller, but if i need to use legacy again ill check throught that way, Thanks!
Answer by aero80 · Dec 04, 2014 at 01:19 PM
Sounds like an animation layer issue. There should be a video about mechanim on learn section or unite where they show a character wave his hand while running at the same time. You should check that out.
Yes, its working with animator controller layers now, thanks.
Your answer
Follow this Question
Related Questions
Rendering FBX with multiple animations 1 Answer
Broken animation in URP project. 2 Answers
3ds Max animation import 1 Answer
Blender FBX import model with animation issues 0 Answers
Scale animation with model 1 Answer