- Home /
Trigger Animation Instantly?
Hey!
I'm trying to trigger an animation on a button press, unfortunately it doesn't seem to respond within a decent amount of time - let alone the near instantaneous behavior I'm looking for. Basically player presses a button and I expect him to change from one animation state to the other. However it takes way too long (haven't actually timed it) for it to happen.
Here's the code (called from a method that is called in the Update() loop)
if (_nextGem != null && Input.GetKeyDown(_laneButtons[NOTE_LANE.Bottom])) {
_gemSmashers[(int)NOTE_LANE.Bottom].GetChild(0).GetComponent<GemSmasher>().onSmash();
checkHit(NOTE_LANE.Bottom, (Time.time * 1000.0) - _start);
}
.
.
.
private void checkHit(NOTE_LANE lane, double time) {
_characterAvatar.SetTrigger("RideToOlly");
.
.
.
That's the only code that deals with animation currently.
Attached are some pictures of the animation controller.
I'm not sure if this is an issue with my code, or with how I've handled the transition in the controller. I've tried adjusting the exit time in the transition, I've tried the different update modes, etc. Nothing seems to be having an effect. =S
Help would be appreciated!
Answer by fryedrycestyle · Jan 21, 2015 at 03:48 AM
Alright, answering my own question is probably poor form BUT, I managed to figured it out. I removed the exitTime condition from the transition and VIOLA it works!
Oh, I didn't spot that! Answering your own question when you found a better solution than any offered and then marking your own question as accepted is completely kosher, as that will show the question as resolved and move it out of the queue of non-resolved answers.
Answer by Baste · Jan 20, 2015 at 09:07 AM
You need to make the transition time smaller. You see that blue outline in the inspector which shows the transition from Riding to Olly? That signifies the length of the blending between the two animations. If that's shorter, you'll get the change in animation much more quickly - though if it's too short, things might look bad as your model "snaps" to the new state
Just grab the arrows on it to make it narrower. If you need to sometimes jump to the animation, and sometimes let it blend naturally, set up two different transitions and give them different setups.
Yeah, I had set that really small at one stage (like to the point where it was just a single blue line vertically), but there was/is still noticeable lag between the button press and the animation playing.
Hmm...
Basically I'm making a music game where the player is essentially skateboarding and the trick animations are played when the notes are hit (similar to Guitar Hero). At the moment we only have the two animations listed, but my artist will making more. I mention this b/c we want to have a system where hitting more notes in rapid succession mixes up the animations played to look like the player is perfor$$anonymous$$g a string of tricks. But, it seems there may be some lag which could screw things up if there is no other way to decrease the time between input and animation?