Math Broblem

Get help using Construct 2

Post » Tue Apr 08, 2014 5:34 pm

i need explanation for how next event should work:

There is gauge, with dipstick on middle on it, like car's speedometer. Well, this won't work like car one's.

I need event/fuction/etc, that makes on click dipstick go full 360 degrees spin in X seconds, where X is variable i want.

For example, like if X is 1, dipstick goes full 360 degrees spin in one second.
~~~~Jabutosama
B
13
S
3
Posts: 68
Reputation: 1,414

Post » Tue Apr 08, 2014 7:43 pm

Try this:

Let's assume you want to rotate an object "Stick".

Give Stick a boolean: Stick.Rotating and set it to false.
Declare variable Stick.Rot_Time = x (where x is the time you want the stick to take to rotate 360 degrees).
Declare Stick.Start_Angle = Stick.Angle (the starting angle, in case it's not zero).

Then, when you want to rotate the Stick, set Stick.Rotating = True and use the following code:

Code: Select all
If Stick.Rotating = True:
>  Trigger once: Set Stick.Start_Angle to Stick_Angle
>  Set Stick.Angle to Stick.Angle + (360 * dt / Stick.Rot_Time)  -- this will rotate clockwise, use a minus to rotate anti-clockwise
>  If Stick.Angle is within 2 degrees of Stick.Start_angle  -- this stops the stick at 1 rotation**
>->  Set Stick.Rotating to False
>->  Set Stick.Angle to Stick.Start_Angle


** It won't work if you want it to rotate in less than 1.5 seconds because that is 4 degrees per tick at 60 fps. If the rotation rate is any faster and/or the framerate drops then it could miss this check window and carry on spinning. If that happens, just use a wider window...

An alternative would be to have a look at the plugins - you could use Rex's Rotate To plugin for this as well.
A big fan of JavaScript.
B
74
S
20
G
69
Posts: 2,212
Reputation: 43,846

Post » Thu Apr 10, 2014 2:52 pm

thank you.
~~~~Jabutosama
B
13
S
3
Posts: 68
Reputation: 1,414

Post » Thu Apr 10, 2014 3:24 pm

@Jabutosama, I just had a thought - a tidier way of managing which direction to rotate would be to leave the code as is and just use negative time values for Stick.Rot_Time if you want the Stick to rotate in an anti-clockwise direction. Can't believe I didn't think of that first go!
A big fan of JavaScript.
B
74
S
20
G
69
Posts: 2,212
Reputation: 43,846


Return to How do I....?

Who is online

Users browsing this forum: ChoosyZerk, dop2000, Lancifer and 53 guests