Discuss Scratch

sockeye-d
Scratcher
47 posts

Help with my easing script

Hi,
I've been getting comments about people not understanding how to use my easing function, so here is a (hopefully) more in-depth explanation.
What is easing?
Well, you can look at it like you're remapping time. You can graph an easing function by doing position over time, or non-linear time over linear time. A linear ease function is as simple as:
define Ease (x)
set [return v] to (x)
This yields a curve like
Okay, now I know what easing is, how do I use your block?
Well, I made the block
Ease () <> <> <> () :: custom block
but the inputs may be confusing. Here are the list of inputs:
Ease (Input time) <In?> <Out?> <Reversed?> (power) :: custom block
//input time is linear
This is the curve checking <In?> gives with a power of 3

This is the curve checking <Out?> gives with a power of 3

This is the curve checking both <In?> and <Out?> gives with a power of 3

((a)*((1)-(t)))+((b)*(t)) // This is a weighted average.
// You set the "t" variable from a value from 0-1 and it will transition between "a" and "b".
//The simplest way to use this block:
define Go From (x1) (y1) to (x2) (y2) in (t) seconds
set [time v] to (0)
repeat((t)*(30))
go to x: (((x1)*((1)-(time)))+((x2)*(time))) y: (((y1)*((1)-(time)))+((y2)*(time)))
change [time v] by ((1)/((t)*(30))
end
This will give you linear interpolation, like the first graph. If you want something smoother, use:
define Go From (x1) (y1) to (x2) (y2) in (t) seconds
set [time v] to (0)
repeat((t)*(30))
Ease (time) <> <> <> () :: custom block // Set the inputs to whatever you like.
go to x: (((x1)*((1)-(return_t)))+((x2)*(return_t))) y: (((y1)*((1)-(return_t)))+((y2)*(return_t)))
change [time v] by ((1)/((t)*(30))
end
But, what if we want to make it FPS independent, so that the animation won't lag even if the project does? Then we can do this:
define Go From (x1) (y1) to (x2) (y2) in (t) seconds
set [time v] to (timer)
repeat until <((timer)-(time))>(t)>
Ease (((timer)-(time)) / (t)) <> <> <> () :: custom block // Set the inputs to whatever you like.
go to x: (((x1)*((1)-(return_t)))+((x2)*(return_t))) y: (((y1)*((1)-(return_t)))+((y2)*(return_t)))
end
I suggest experimenting with this ease block and weighted average combo, and with the inputs of the ease block. (Try powers less than one! It yields very interesting curves!)
Anyway, that concludes my explanation. I hope you learned something, and ask any questions that you have (as long as they're on-topic)!

Last edited by sockeye-d (Jan. 16, 2021 18:58:14)


I like baked potatoes
click to see how many messages I have
click to see how many messages griffpatch has
eat(bake(sockeye-d's potato :: #888) :: #666) :: #444










Regular platformer: Platformer
Generic platformer: Platformer<T>
Oumuamua
Scratcher
1000+ posts

Help with my easing script

Nice!


quashposh
Scratcher
6 posts

Help with my easing script


I got out of whirlpool

Let's go woo-hoo
Oh no
I'm getting sucked into a tornado
HELP


If you actually recognize this
-RDev-
Scratcher
15 posts

Help with my easing script

coooooooooooooool????
yarrro
Scratcher
3 posts

Help with my easing script

Octozan
Scratcher
1 post

Help with my easing script

yeet
han614698
Scratcher
1000+ posts

Help with my easing script

Hey guys - please do skip skip the necroposting.

<Scratch Wikian | Forum Helper | Almost to 6000 Posts! | Please be aware I may mistype things, my wrist is fractured>

Credit to -gge for the icons in my signature | I condensed all this code into five lines using [p] tags, idk why




Powered by DjangoBB