Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • 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
1
Question by mathmos_ · Jun 17, 2013 at 07:36 AM · animationanimatorcharactermecanim

Dynamic Mecanim animation speed/time

Hi,

I'm currently working on implementing a weapons system, that features many different guns with different reload times and rates of fire. I need to shorten or lengthen character animations based to these weapon stats. Is there any way to dynamically alter the speed of animations from code in mecanim, or maybe just stop an animation state?

The workaround in this doesn't apply in this case as far as I can tell. Any ideas?

Comment
Add comment
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

1 Reply

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

Answer by TonyLi · Jun 17, 2013 at 01:27 PM

The forum thread covers a couple different ideas. I'm not sure which one doesn't apply. Here are some options to consider:

  • Set playback of the entire Animator using Animator.speed. Note that this overrides the speeds of all states in your controller. Probably not your best bet.

  • Set up different states using the same animation clip but with different speeds. Transition to the right state based on the current weapon.

  • Use a blend tree to blend between different versions of the same animation clip that are set to different speeds. This is a common solution to this problem, as you have very fine control of the speed.

  • (Undocumented and unsupported:) Dig into the internals of the controller: http://answers.unity3d.com/questions/418854/getting-a-list-of-mecanim-states-in-animator.html

Comment
Add comment · Show 7 · 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 mathmos_ · Jun 17, 2013 at 01:47 PM 0
Share

How would go about solving this with a blend tree?

avatar image mathmos_ · Jun 17, 2013 at 02:19 PM 0
Share

And is it possible to stop an animation and play it from the beginning?

avatar image TonyLi · Jun 17, 2013 at 04:05 PM 2
Share

How would go about solving this with a blend tree?

Here's one way:

  1. Create a float parameter named reloadSpeed.

  2. Create a blend tree based on reloadSpeed.

  3. Add two motion fields. Assign the reload animation to both motion fields. Set the speed of the first one to the $$anonymous$$imum reload speed, and the speed of the second one to the maximum reload speed.

When you change weapons, call Animator.SetFloat("reloadSpeed", X), where X=0 is the slowest speed and X=1 is the fastest. X=0.5 would be the speed right in between.

And is it possible to stop an animation and play it from the beginning?

Create a transition to a null state and back. Trigger the transition on a boolean parameter called "restart" or something like that.

avatar image mathmos_ · Jun 17, 2013 at 06:15 PM 0
Share

That should do it. Thanks a lot.

avatar image mathmos_ · Jun 18, 2013 at 09:26 AM 0
Share

I'm having trouble with restarting an animation. I need to restart a firing animation if the firing animation is already playing, and the player tries to fire again.

I have made a transition to a null state on a isRestarting boolean and an instant transition back to the firing animation, but it's not working. I set the isRestarting boolean on an event if we are already in the firing state, but that check does not always return true, even if it is in the firing state. I guess that check can only be made in Update. I reset isRestarting in Update if we are in the null state, and I reset isFiring if we are in the firing state.

How should this be implemented?

Show more comments

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.

Follow this Question

Answers Answers and Comments

15 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

Related Questions

Mecanim issue: Twitching when blending into blendtrees 1 Answer

Animator System doesnt work! 1 Answer

Cannot restart animation in Mecanim 3 Answers

Changing how my character looks depending on his current lifes. 2 Answers

Mecanim animation issue 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