Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 Sarmale32 · Mar 16, 2017 at 08:30 PM · animationscripting problem

How to make the animation run longer or shorter?

So i have the player,which is a cube and i want it to "jump" to a chosen empty object position.I managed to move the player from it's original place with vector3.MoveTwords(),but in the same time i want to play an animation that shows the cube how it jumps to the empty object position,the problem here is that the empty object position will change so the distance from the cube to te empty object will be different,in this case i need to change the time that it takes the animation to complete,so it does not play and after that let the cube move just in a straight line...I want the animation to take a longer or shorter time to run,giving that the empty object position will always change...

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
0

Answer by jjcrawley · Mar 17, 2017 at 01:19 AM

Depends what you mean by run longer. If it's playback speed, then you're after the Animator Controller that is playing the animation for that gameobject. Once you have that, it is a simple case of setting the playback speed.

 public Animator myAnimator;
 
 void Start()
 {
       //if you haven't assigned one, grab the one on this object
       if(myAnimator == null)
       {
             myAnimator = GetComponent<Animator>();
       }
 }
 
 void UpdateSpeed(float speed)
 {
       myAnimator.speed = speed;
 }

 //this would allow you to specify how long you want the animation to play for, not essential but may prove useful. This should allow the speed to be setup so that the animation will end in playTime seconds
 void SetSpeed(float animationLength , float playTime)
 {
       //speed is a ratio between the actual clip length, and how long you want it to play for. 
       float speed = animationLength / playTime;

       myAnimator.speed = speed;
 }

How you transition in and out of your jump animation is up to you. Don't forget to check the Animator reference docs, may help if speed isn't what you're after. Don't forget to experiment with different things. Also, don't forget to reset the speed when you're finished with it. The playback speed controls the speed of the Animator component, which will affect any animation inside the assigned controller.

Hopefully this helps.

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

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Change walking anim if gun is picked up? 1 Answer

How can i use the Animator in script to find when animation clip finished playing and then stopping the animation ? 1 Answer

How can I use IK with AnimationClipPlayable or AnimationMixerPlayable? 1 Answer

How do I stop moving when attacking? 1 Answer

Can I make animations snap to a frame? 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