Some maths

Get help using Construct 2

Post » Thu Dec 18, 2014 1:28 pm

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.


Many thanks
B
9
S
3
G
1
Posts: 128
Reputation: 1,116

Post » Thu Dec 18, 2014 1:37 pm

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
Game design is all about decomposing the core of your game so it becomes simple instructions.
B
53
S
22
G
18
Posts: 2,122
Reputation: 17,123

Post » Thu Dec 18, 2014 2:49 pm

Thanks! works :3
B
9
S
3
G
1
Posts: 128
Reputation: 1,116


Return to How do I....?

Who is online

Users browsing this forum: evillair, mongoose665, OBLIVION, Yahoo [Bot] and 68 guests