Maths problem for your brain

Get help using Construct 2

Post » Thu Nov 10, 2016 2:36 pm

Hello dear community of C2 :)
I have a complex (for me) maths problem that I can't wrap my head around... I think it must involve using lerp(a,b,x) but I'm not quite sure how to achieve this..

I have two objects. Object A must influence Object B.
Object A moves from speed 0 to 100
Object B has a size of 36 x 36

Now I want the size of Object B to adapt according to the speed of Object A on a scale.
The fastest Object A goes, the flattest and widest Object B gets. when Object A's speed is maximum (100) Object B must have a width of 150 from initial width of 36
and height of 3 from initial height of 36 (kinda like a jelly cube which would flatten and spread then go back to its original size.

So when Object A's speed = 0 Object B size = 36 x 36. When object A's speed is 100 then Object B size = 150 width x 3 height

Which gives us:
OBJECT A SPEED RANGE: 0___________________________________100
OBJECT B WIDTH RANGE: 36_________________________________150
OBJET B HEIGHT RANGE: 36__________________________________3

If Object A's speed = 50, then Object B Width should be 57 and Height 16,5. How can I obtain both those numbers dynamically? I'm pretty sure lerp must be used..

I'm not sure if the example I've used is very clear. My brain is melting even tho I suspect it's not THAT complicated :)
B
17
S
3
G
3
Posts: 89
Reputation: 2,825

Post » Thu Nov 10, 2016 2:52 pm

If A's speed is 50, and if its a linear evolution, then B width should be 93, not 57 and height should be 19.5, not 16.5.
Check again.

The formula can be something like this:

B.width = 36 + (A.speed * 1,14);
B.height = 36 - (A.speed * 0,33);


Edit: re-read and i think you want it to change exponentially, right? Let's wait then :P
English is not my native language. Sorry for any mistakes and feel free to correct me if needed.
B
14
S
5
G
3
Posts: 113
Reputation: 3,231

Post » Thu Nov 10, 2016 3:06 pm

@Cassianno You are absolutely right! I checked and it works! I feel very stupid now. Lerp not even needed! Hahah
Thank you very much for your help Cassianno!
B
17
S
3
G
3
Posts: 89
Reputation: 2,825

Post » Thu Nov 10, 2016 3:43 pm

Woot, nice =)

Btw:
1,14 = (150-36)/100
0,33 = (3-36)/100
English is not my native language. Sorry for any mistakes and feel free to correct me if needed.
B
14
S
5
G
3
Posts: 113
Reputation: 3,231

Post » Thu Nov 10, 2016 3:47 pm

Thanks, I need that formula more often than I think and I always end up doing more complicated stuff than necessary.
B
17
S
3
G
3
Posts: 89
Reputation: 2,825


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 8 guests