• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by absameen · Nov 20, 2011 at 03:29 PM · animationcrossfade

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.

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Owen-Reynolds · Nov 20, 2011 at 07:28 PM 0
Share

time/Length is computed for you in normalizedTime.

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

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."

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image absameen · Nov 21, 2011 at 12:58 PM 0
Share

This works great!

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

How to use CrossFade with anim2 when anim1 is over? 1 Answer

Can the animation editor create local rotational data? 3 Answers

Why is Animation Not Playing in Reverse? 2 Answers

Animation/CrossFade difficulties, Animation won't CrossFade 0 Answers

How to make an animation finish after looping smoothly? 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges