Turn Acceleration

Get help using Construct 2

Post » Mon Aug 13, 2012 10:43 pm

Hi,

I have currently, "when left arrow is down" - "set 'turn left' to true" - "turn left = true" - "rotate 'sprite' 1.5 degrees counter clockwise"

This is great for turn accuracy, but I want it so that, the longer the player holds down 'left' the faster the sprite spins. I want a turning acceleration, so that way I maintain the accuracy of a low rotation meter but also gain the speed off a faster one.

Can anyone help with this?

Thanks,
MikCrudeMik2012-08-13 22:44:52
B
39
S
12
G
8
Posts: 580
Reputation: 7,108

Post » Tue Aug 14, 2012 2:26 am

Instead of setting the rotation to a fixed 1.5 degrees, create a variable with an initial value of 0, and rotate the object according to said variable*dt.

In addition, when left arrow is down, set 'turn left' to true AND increase the value of the variable by a fixed amount multiplied by dt (add 0.5*dt to variable).

To turn the other way, subtract instead of adding.

If you want to limit the maximum/minimum turning speed, whenever you would add or subtract to that variable, instead of adding or subtracting set the variable value to clamp(variable[+/-]<amount>,<min>,<max>) (see here for details).

don't forget to multiply stuff by dt, otherwise things will go really fast.

I hope this helped!
B
35
S
8
G
8
Posts: 532
Reputation: 6,868

Post » Tue Aug 14, 2012 9:32 am

Ah excellent, I keep forgetting about dt, I don't fully understand it yet - I will learn.

I'm still doing things like "every 0.2 seconds" "spawn bullet" and stuff like that. Not good.

The 'clamp' variable function is new to me too, but that makes sense.

Thanks!
B
39
S
12
G
8
Posts: 580
Reputation: 7,108

Post » Tue Aug 14, 2012 9:39 pm

nothing wrong with "every 2 seconds -> spawn bullet" actually :)
You use dt for situations like "every 1 second -> move object 10 to the right" which then become "every tick -> move object 10*dt to the right", which serves to make the motion smooth.
For instance, instead of "when the up arrow is held down -> increase acceleration by 5", change to "increase acceleration by 5*dt" and the object will accelerate 5 pixels per second per second :)
B
35
S
8
G
8
Posts: 532
Reputation: 6,868

Post » Tue Aug 14, 2012 9:43 pm

@Fimbul, I wish I could give you a Eureka! badge. You just caused my brain to finally understand dt. Augmented neural pathways FTW!Wastrel2012-08-14 21:44:34
Don't see the fnords and they won't eat you!
B
75
S
16
G
12
Posts: 322
Reputation: 11,608

Post » Wed Aug 15, 2012 12:00 pm

Brilliant, yeah fantastic, the turn acceleration works really well. Thanks!
B
39
S
12
G
8
Posts: 580
Reputation: 7,108


Return to How do I....?

Who is online

Users browsing this forum: flemmig, Google [Bot], Jarnopa, semaso, Skebab and 12 guests