• 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
Question by xpavelos · Jun 14, 2016 at 04:54 PM · animationtimespeed

Play whole animation over specified time via script

Hello. ;)

I don't just want to change the speed of animation. I want to have control of animation state in seconds - e.g. If I put 0.5 in the inspector the animation will play for 0.5s displaying all frames over that time.

For example - character has attackSpeed variable, when its set to 0.5f I want the attack animation play for exactly 0,5 seconds (no matter how many frames are there, all frames must be displayed over that time).

I'm not sure if there is a proper way to do it, or should I just figure out some workaround like calculating frames per second with animation speed? Any ideas?

Comment

People who like this

0 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 Dibbie · Jun 14, 2016 at 06:00 PM 0
Share

I dont really think thats physically possible? You want to play, lets say a 3 second animation, in 0.5 seconds, but you dont want the animations speed to be any faster? (altering the animations speed variable does exactly what your describing) - if you calculate how long it takes for your player to swing and actually hit your enemy, you can add (or subtract) that time from the animation speed, which is probably the easiest way to get to as close as what your trying to achieve.

1 Reply

  • Sort: 
avatar image
Best Answer

Answer by xpavelos · Jun 14, 2016 at 11:18 PM

Thanks for your comment Dibbie. But that's not what I was looking for.

I found an easy way to achieve it. First, I must assume that animation must be exactly 1 second long. And when I set attack speed to 0.5, which is half a second then animation speed must be doubled - in this case must equal 2 (and now animation also lasts half a second). And if I set attackSpeed to 2 seconds, animation speed must be slowed down to 0.5. This is how I solved it:

     public void SetAttackSpeed(float value)
     {
         attackSpeed = value;
         upperAnim.SetFloat("attackSpeed", 1/value);
     }

The "attackSpeed" parameter in upperAnim is used as a multiplier parameter.

Comment

People who like this

0 Show 0 · 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

Unity Answers is in Read-Only mode

Unity Answers content will be migrated to a new Community platform and we are aiming to launch a public beta on June 13. Please note, Unity Answers is now in read-only so we can prepare for the final data migration.

For more information and updates, please read our full announcement thread in the Unity Forum.

Follow this Question

Answers Answers and Comments

86 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Clamp animation to a certain amount of time? 1 Answer

[Solved] Reverse animation help 2 Answers

animation to play faster over time 2 Answers

Animation Stop and Stay 1 Answer

How do I play muiltiple animations? 1 Answer


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