Turn Acceleration

0 favourites
  • 6 posts
From the Asset Store
A well commented RPG game template to learn from or use as a base for your own game!
  • 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,

    Mik

  • 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!

  • 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!

  • 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 :)

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Fimbul, I wish I could give you a Eureka! badge. You just caused my brain to finally understand dt. Augmented neural pathways FTW!

  • Brilliant, yeah fantastic, the turn acceleration works really well. Thanks!

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)