Do you have any pretty formula to smoothly calculate the scale of an object depending of its Y position?
For instance i want a sprite to change its scale based on the max Y (y=480 then scale=1) and the min Y (y=340 then scale=0.8)
This formula will trigger every tick.
Time to lerp!
unlerp(340, 480, Sprite.Y) will return 0 if sprite.y is 340,1 if sprite.y is 480, and interpolates with a affine function between those values (0.5 will be for sprite.y of 410)
lerp(0.8, 1, A) will return 0.8 for A =0, 1 for A =1, and interpolate with an affine function between.
combined with lerp, you can do:
lerp(0.8, 1,unlerp(340, 480, Sprite.Y)), which should return 0.8 for sprite.y being 340, 1 for sprite.y being 480, 0.9 for sprite.y being 410.
hope I am correct
Develop games in your browser. Powerful, performant & highly capable.
Thanks! works :3