- Home /
Set the current time / frame of a Mecanim animation
Using the old system this is easy to do:
animation["Walk"].normalizedTime = 0.5F;
Gives us the middle point of the animation. Is this possible using Mecanim?
Answer by komodor · Jan 24, 2014 at 12:16 AM
dunno, but now you can do just:
Animator.Play(state, layer, normalizedTime);
if you use
Animator.Play("same state you are", -1, 0f);
it will restart current state, if you put whatever float from 0 to 1 into normalized time, you can set it to any time position you want
you can also use
Animator.CrossFade(state, crossFadeTime, layer, normalizedTime);
Has anyone been able to solve this problem yet?
In the old animations, my code waited for the midpoint of an animation to calculate whether or not something got hit. Under mecanim, I have no idea how to do this.
In my old system, I did this:
animTime = $$anonymous$$athf.Round(Animation[myBody.attack1].normalizedTime * 10)/10; if (animTime == 0.5f) {
do something
}
Does anyone know how to do this using mecanim?
maybe you should start your own question, because nobody will find this
i believe you can achieve this by animation events with or without mecanim http://docs.unity3d.com/Documentation/Components/animeditor-AnimationEvents.html
Answer by piacentini · May 18, 2015 at 10:35 PM
As I stumbled across this issue as well, here is my simple solution now that ForceStateNormalizedTime is deprecated (Unity 5)
animatorcomponent.Play("yourste", -1, 0.5f);
animatorcomponent.speed = 0;
If you do not set the speed to 0 the animation will simply play from the new initial frame until the end.
Answer by simsimsim · Aug 28, 2013 at 09:53 AM
In mecanim you can set the normalized where to start the animation in the transition.
To start a walk cycle with the other foot (left instead of right) you could create a boolean parameter named RightFootFirst. Then in the transition from idle to walk check if the RightFootFirst is true also. Create an other transition which is identical except thet now it RightFootFirst needs to be false and then set the offset of the walk state to 50%.
Answer by 10yaseen1 · May 07, 2013 at 10:59 AM
you can use the new Mecanim system in unity 4 which also supports the nomalised time function, for example
function Update (){
if(animator){
if(basecurrentstate.IsName("Base Layer.AIM")){
animator.ForceStateNormalizedTime(1.0);
}
}
}
but remember it works for the Base Layer only. Hope it helped, Good Luck :)
Answer by tgraupmann · Dec 28, 2013 at 05:46 AM
If you have a longer animation, you can see the current playing state completely ignores the deprecated ForceStateNormalizedTime.