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 phatpixels · May 21, 2014 at 03:00 PM · animationvariabletimespeed

animation to play faster over time

Hello, I am trying to have my animations play faster as time goes along. referring to a timer script. this is what i have, it recognises and prints time, but doesnt speed-up the animations. a novice at scripting here :(

function Update () {

 print(other.score);
 
 if (other.score >= 0){
 
 
 animation.PlayQueued(anims[Random.Range(0, anims.length)]).speed = animspeed;
 
 }
 
 
 
 if (other.score >= 4){
 
 animspeed = 2f;
 
 
 }
 
  
 if (other.score >= 15){
 
 animspeed =7f;
 
 }
 
 }
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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by CorruptedTNC · May 21, 2014 at 03:14 PM

If you want to modify the speed of an animation, you'll have to use AnimationState.speed as this has a speed property you can set. As per the documentation 1f or 1.0f is regular speed, 2f/2.0f is double and -1f/-1.0f is regular speed backwards.

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 phatpixels · May 21, 2014 at 03:19 PM 0
Share

Ok. so i should drop all the var animspeed and just refer to it as speed. I will try this now. Thankyou )

avatar image
0

Answer by Andres-Fernandez · May 21, 2014 at 03:14 PM

You are almost there. AnimationState.speed changes the speed of the animation clip. Take a look at the example.

Comment
Add comment · Show 6 · 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 phatpixels · May 21, 2014 at 03:29 PM 0
Share

still believe im missing something though, i mean animation works as it should ,but, the animations do not pick up speed.

pragma strict

var speed : float; var anims = ["Roll", "Spin"]; var model: GameObject; var other : time;

 function Update () {
 
 print(other.score);
 
 
 
 animation.PlayQueued(anims[Random.Range(0, anims.length)]).speed = 1;
 
 }
 
 
 if (other.score >= 4){
 
 speed = 2;
 
 
 }
 
  
 if (other.score >= 15){
 
 speed =7;
 
 }
 
avatar image Andres-Fernandez · May 21, 2014 at 04:02 PM 0
Share

Ins$$anonymous$$d of using speed = 7; (or whatever) inside your if statements, you have to set the speed of each animation state. Something like:

 if (other.score >= 15) {
    for (int i=0; i<anims.length; i++) {
       anims[i].speed = 7;
    }
 }

(i'm not a javascript coder, and just typed out of memory)

avatar image phatpixels · May 22, 2014 at 11:30 AM 1
Share

Thankyou Andres, i know im getting close. At the mometn it is still not functioning as i need. The speed increases in the inspector, but the animations are not affected, i cant figure it out. ill keep trying. thanks again.

 #pragma strict
 var speed : int = 0;
 var anims = ["Roll", "Spin"];
 var model: GameObject;
 var other : time;
 
 
 
 function Update () {
 
 print(other.score);
 
 animation.PlayQueued(anims[Random.Range(0, anims.length)]).speed=speed;
 
 
  
     if (other.score >= 7) {
     
    for(var i : int =0; i<anims.length; i++)
    {
     Debug.Log("hurry");
   speed =7;
     }
    }
    }
avatar image Andres-Fernandez · May 23, 2014 at 06:45 AM 0
Share

You get the AnimationState in the play function, but I suggest you set the time before that (check here to see how to get the AnimationState). Something like:

 function Update() {
    // Get the random index of the clip
    var randomIndex : int;
    randomIndex = Random.Range(0, anims.length);
 
    // Set the speed of the clip, getting the clip from the animation component
    animation[anims[randomIndex]].speed = speed;
    // Then play it
    animation.PlayQueued(anims[randomIndex]);
 
    // Do the rest of the stuff
    if (other.score >= 7) {
       speed = 7;
    }
 }

(Again, I'm not a JavaScript coder, sorry for the mistakes)

avatar image phatpixels · May 23, 2014 at 08:31 AM 1
Share

Hi Andres, no mistakes :) the script you wrote is much more elegant than $$anonymous$$e. $$anonymous$$any thanks, although it still doesnt alter the speed from the if statement.....i cannot understand why. I will keep adjusting the script to find an answer, i will let you know. i appreciate all your help, thankyou kindly.

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

22 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

Related Questions

Animation Stop and Stay 1 Answer

Play whole animation over specified time via script 1 Answer

Clamp animation to a certain amount of time? 1 Answer

[Solved] Reverse animation help 2 Answers

Float var to control animation speed? 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