AnimatorController use with little or no scripting
Scenario:
I have an object that I want to execute 1 or more animations to based on certain scenarios. I have a fadeIn animation that adjusts the material alpha to fade the object from invisible to visible. I have a fadeOut animation that adjusts the material alpha the opposite way. I have a rotate animation that rotates the object. I want the object to start rotating once a flag is turned on and then stop when it is turned off. This works fine by itself but messes up when using the fading animations. The fadeIn and fadeOut animations should trigger when requested in code but then not loop nor reset. As in once fadeIn finishes it is in a visible state and stays that way until the visibility/fade state(s) are adjusted. Similarly for fadeOut and invisible state.
The problem:
Now, based on what I have read you should be able to simulate this scenario in the animator controller before committing it to code but for some reason it doesn't want to work. Either it stops rotating for no reason or it fades in and out continuosly.
The questions:
1. Is such a scenario possible? 2. Do I have to use the Any State transition to each state animation? I have tried this but it didn't work that way either, so maybe I have misunderstood its use despite all the videos I have watched. 3. Can I use the Any State transition to the fadeIn, fadeOut and rotate animations and then have fadeIn move to Visible and fadeOut to Invisible but keep them there with no other animations triggering? This also seems to be ignored and the animations either stutter part way through or constantly repeat. 4. Or do I have to make sure that every scenario is monitored in script and the code controls when each animation starts and stops. In which case what is the animation controller for if not to control when the animations are run or not.
If someone recognises these problems and can point me to what is causing them it would be appreciated.
Thanks in advance.
Answer by Xrystal · Sep 08, 2016 at 11:35 PM
Well I think I have it figured out. It may not be perfect but it's working the way I expected. Thought I would post my success in reply in case someone else hits a similar bump in their process.
Triggers:
Rotate
FadeOut
FadeIn
Animations:
Rotation - Rotates the animated object on its Y axis using Quaternion (Euler) interpolation with 0:00 set to 0 degrees and x:00 set to 360 degrees. End time set dependent on spin speed required. Should be code changeable if required. Add the following in Start to start the rotating off.
animController.SetTrigger( "Rotate" );
Screenshot:
FadeIn - Fades the renderer material alpha from 0 to 1 over x:00 time based on speed of fade process. It should stay in that final status until the next status change. The following code to placed in the appropriate code block to activate the process. My simple example used the Update routine with a key press to activate it.
animController.SetTrigger( "FadeIn" );
while (animController.GetCurrentAnimatorStateInfo( 1 ).IsName( "FadeIn" ))
isAnimating = true;
isAnimating = false;
FadeOut - Works similar to the Fade In process except it goes from 1 to 0.
Your answer
Follow this Question
Related Questions
How do I know what animation I can transit to in the animator, from my current animation? 0 Answers
Why is the last frame of the animation not triggering? 0 Answers
Script animation 2d question,Script animation 2d 0 Answers
How do I change the exit time of Animator Override Controllers? 0 Answers
Animation won't play 0 Answers