- Home /
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;
}
}
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.
Ok. so i should drop all the var animspeed and just refer to it as speed. I will try this now. Thankyou )
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.
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;
}
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)
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;
}
}
}
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)
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.
Your answer
Follow this Question
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