- Home /
Problem with 'animation.CrossFade' and 'fadeLength'.
Greetings! This is my very first post on the forums.
I've been developing a third person shooter over the last couple of weeks in order to learn unity so far I've found everything I've needed by browsing old posts here and reading the scripting manual but now I've been stuck with this probably simple problem for way to many hours..
I have a setup where holding the Mouse2 button moves the camera to look over the shoulder, (Resident Evil/Mass Effect style). At the moment I just use a 1 frame pose of the character aiming down the sights of a rifle. In order to blend into this pose I use, the following from inside LateUpdate (have other animations playing underneath):
animation.CrossFade("aim",aimDelay); //for full body aiming stance.
animation.CrossFade("aimUpperBody",aimDelay); //for aiming while walking.
Where aimDelay is of course a float value. Problem is the delay works only the first time character shoulders the weapon, after that it snaps into position instantaneously. Testing everything I could think of I noticed that when raising the 'aimDelay' from what it's supposed to be (in the order of a fraction of a sec) to something very high like half a minute - if mouse2 is released prematurely, before weapon is fully raised, pressing it again will continue to raise the weapon from the point it had previously reached, like 50% raised at 15 seconds etc. Like the aimDelay value is a pool of time that the crossFade keep chewing up til' empty.
I've tried all sort of crazy things including the obvious not so crazy stuff like rewinding the animation before doing the crossFade tested different wrapping modes, multiply by Time.deltaTime or do a 'curTime' strip of the time etc, but no joy.
I figure I can always go into max and just animate the sequence and solve it that way, but I also feel to stubborn to surrender. reading the forums I notice no one seems to have any similar issues so I can't shake that I may be missing something obv?
If I may be as rude as to sneak in a bonus question:
I feel I have a very similar problem with all my 'yield WaitForSeconds(x)'in functions that they just do the wait the first time a function is called and then pass straight past the 'yield' every time?
If anyone could tell me what's up with that I'd be a very happy man for several minutes, perhaps even a full hour.
Thanks for reading!
Can't really help you on the CrossFade problems, but I can tell you that yield WaitForSeconds( t ) should definitely wait t seconds every time. For instance:
function YieldExample()
{
while( 1 > 0 )
{
Debug.Log("something")
yield WaitForSeconds( 2.5 );
}
}
will, after being called once, Log Something every 2.5 seconds.
Your answer
Follow this Question
Related Questions
Loop Animation with delay-variable 1 Answer
Loop animation with a wait in between 3 Answers
Yield waitforseconds not consistent for animation-unity2D 0 Answers
Yield until animation is over? 1 Answer
WaitForSeconds vs yield every frame 3 Answers