Variable animation speed?
MattSoden
Member Posts: 30
Bit of an odd one, but is it possible to shoehorn two of @Socks' specialities together to make a variable fps animation?
Using the Fast Frame Swap formula -
floor((self.Time*fps)%number_of_frames)
but replacing the fixed fps with a sin function I came to -
floor((self.Time*sin(self.time*30))%number_of_frames)
hoping that this would work, and it does to a degree, but it seems to create increasingly high fps values that eventually just become too fast to behave how I'd like them to (ie the amplitude of the sine wave is slowly increasing?)
How would I go about fixing the minimum fps value to 12fps and the max to 30fps whilst still having the sin wave 'ramp up' and 'slow down'?
I have a bubbling Eldritch horror that awaits an answer...
Comments
I think it should be . . .
floor((9 *sin(self.time *30)+21)%number_of_frames)
. . . hold on, I'll just test it out . . .
Maybe I've misunderstood what you want ?
The formula I posted above works (except you need to change the 'floor' for a 'round' otherwise you never get to the very top of the sine wave (using 'food' means you stop at 29 rather than 30 in the value range) . . . but if I understand this right it 'swings' from one value to another, from 12 to 30, with a dampened return at each end of the swing . . . but that would simply be the frame number changing . . . is that right ?
round((9 *sin(self.time *30)+21)%number_of_frames)
Coincidently this is exactly what I am doing in a current project !
A thought !
Because you are using a sine wave to swing between two values you have no need for the 'mod' loop ('%number_of_frames'), as the values never get bigger (or smaller) than the 12 to 30 range . . . so the formula can be a little more simple, like this:
round(9 *sin(self.time *30)+21)
. . . which now makes me think I've misunderstood what you are after ! Lol !
I'm now thinking that you have a looped animation that you want the frame rate (not the frame) to swing up and down in value - that is to get faster and slower and faster . . .
?
Back to the drawing board . . .
I think that you've got it correct Socks - I have a cute Lovecraftian horror that uses 30 frames of animation to pulse and change shape (the animation is cyclic, so frame 30 leads to frame 1 seamlessly) that I am running at a steady 30fps using your fast frame swap formula.
I wanted to make the frame rate of the animation pulse as well to add an extra level of variety - at one moment the fps would be 15fps then a few seconds later it would speed up to 30fps then slow again to 15fps.
I'll keep tinkering.
I'm not sure it is possible with the way you have it set up (and the way I set it up in my examples) as you are trying to animate the speed of the speed ! It's not that there is a technical limitation, I just don't think it conceptually makes sense.
This will swing between 12 and 30
9 *sin(self.time *30)+21
. . . . but, and here is where the concept collapses for me, at what speed were you planning to swing between 12fps and 30fps ?
This works - i.e. the frame rate swings between 12fps and 30fps, the '100' is the rate at which the frame rate changes (the speed of the speed !).
round(( self.Time *21)+(9 *sin( self.Time *100)))%50
Thanks @socks - much appreciated!