- Home /
CrossFade to Specific Animation Time (Coordinate Animations)
I have a character that is controlled by the player. I crossfade between running and walking animations regularly. However, it looks like he missteps sometimes when the animations crossfade to the incorrect starting position. Ex. he has his left foot forward but the new animation starts with his right foot forward.
Is it possible to CrossFade from one animation into a specific starting time of another animation?
Edit
I tried the following method:
When crossfading from Walking -> Running
Get the current walking animation time using animation["walk"].time
Calculate the time passed as a ratio:
var ratio = animation["walk"].time / animation["walk"].length // assume Wrap Mode "Once" is used for this example
Crossfade to the running animation, and set the time based on the calculated ratio
animation["run"].time = ratio * animation["run"].length;
animation.CrossFade("run");
This sort of works, but it will need a lot of polish to get it looking good. I'm wondering if anyone has thought of a better solution to solve the misstepping problem.
Answer by Owen-Reynolds · Nov 20, 2011 at 07:26 PM
[Untested] crossFade("run") starts the run animation, at frame 0, and fades out whatever was playing before. The trick is to start run at a different frame:
animation.CrossFade("run"); // restarts run, at frame 0
// assuming walk/run are similar: rightFoot/leftFoot, put run
// in similar position as walk:
animation["run"].normalizedTime = animation["walk"].normalizedTime;
If you're using the set-up where you constantly crossFade to run at high speed (since crossFade when you're already doing it, knows not to restart.) Then you'd have to somehow say "only figure runs new time if I am just now switching, from walk."
Your answer
![](https://koobas.hobune.stream/wayback/20220613050602im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Animation Stop and Stay 1 Answer
Animator.CrossFade or Animator.CrossFadeInInFixedTime does not play animation after crossfading. 0 Answers
How can I smoothly transition my player camera from manual control into an animation? 1 Answer
Animations are different when in lower layers 1 Answer
Animation Doesn't CrossFade At End 0 Answers