Rotate degrees with smooth start/stop?

0 favourites
  • 13 posts
From the Asset Store
Simple resize and rotate events for any sprite, quick and easy event sheet that you can use for your own projects.
  • I can't figure out to use the rotate degrees clockwise action with smooth start and stop of rotation. I'm not sure how to use lerp, or if it is the correct method. Can it be done?

  • Probably the easiest is to have a lot of variables as follows. Pos is a value from 0 to 1 that when used with lerp can give an angle between the start and end angles.

    variable start_angle

    variable end_angle

    variable pos

    every tick

    --> add dt to pos

    pos>1

    ---> set pos to 1

    every tick

    ---> set angle to anglelerp(start_angle, end_angle, pos)

    Start of layout

    ---> set start_angle to 0

    ---> set end_angle to 90

    ---> set pos to 0

    That's the long version. You can simplify it but it becomes less readable.

    The "start of layout" condition is an example how to use it. You need to set the start and end angles and reset pos to 0.

    Also the transition will take one second. You can make it faster or slower by adding another value to "pos".

    Ex.

    2*dt for 0.5 seconds

    0.5*dt for 2 seconds

    0.1*dt for 10 seconds

    Finally it's a linear angle change, although you can make it ease in-out by changing:

    anglelerp(start_angle, end_angle, pos)

    to

    anglelerp(start_angle, end_angle, cubic(0,0,1,1,pos))

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Probably the easiest is to have a lot of variables as follows. Pos is a value from 0 to 1 that when used with lerp can give an angle between the start and end angles.

    variable start_angle

    variable end_angle

    variable pos

    every tick

    --> add dt to pos

    pos>1

    ---> set pos to 1

    every tick

    ---> set angle to anglelerp(start_angle, end_angle, pos)

    Start of layout

    ---> set start_angle to 0

    ---> set end_angle to 90

    ---> set pos to 0

    That's the long version. You can simplify it but it becomes less readable.

    The "start of layout" condition is an example how to use it. You need to set the start and end angles and reset pos to 0.

    Also the transition will take one second. You can make it faster or slower by adding another value to "pos".

    Ex.

    2*dt for 0.5 seconds

    0.5*dt for 2 seconds

    0.1*dt for 10 seconds

    Finally it's a linear angle change, although you can make it ease in-out by changing:

    anglelerp(start_angle, end_angle, pos)

    to

    anglelerp(start_angle, end_angle, cubic(0,0,1,1,pos))

    Thanks, trying this but it seems to use a fixed sort of positionig for the angle, due to using "set the angle"? At the moment, my rotation is using "rotate angle by -100dt degrees", so when it starts and stops rotating, it always sorts and stops from the same point, whereas by using the pos variable, it seems to have a fixed start and stop angle. Can this be adapted for use with "rotate angle by degrees"?

  • I guess you could use a different approach by having a speed variable. The you increase/decrease the speed if the calculated stopping distance less or greater than the anglediff.

    So maybe this?

  • I guess you could use a different approach by having a speed variable. The you increase/decrease the speed if the calculated stopping distance less or greater than the anglediff.

    So maybe this?

    Yes, that's what I was kind of thinking, could an even simpler way involve using "rotate angle by (max(100)(rotatevar))+1)dt) and invert that for the slow down?

  • I don't know. It could be something to try.

  • Is this what you're looking for? https://www.dropbox.com/s/s7i5gp9zc9fzt ... .capx?dl=0

    And this one I made based on R0J0's first post before I read more carefully and realized it wasn't what you're looking for, but I'll leave it here anyway - https://www.dropbox.com/s/u7ktol9qyy166 ... .capx?dl=0

  • oosyrag Thanks, I tried to implement your method into this, and it worked for starting up, but fails for slowing down, it just stops dead. Here's what I'm trying to adapt it to: https://www.dropbox.com/s/3cdl7txdqhizm ... .capx?dl=0

  • I hope it's okay that I post this here (please let me know if it isn't).

    I tried modifying oosyrag 's capx (based on R0J0hound 's method) to allow for a player to hit a switch and lower a bridge. I transitioned the variables from global to local and for some reason that seems to throw a wrench in the anglelerp process. Any idea why that might be? I was thinking it'd be great to add a feature like to this to a larger project but I'm trying to avoid tons of global variables if I can.

    Here's the modified capx:

    https://www.dropbox.com/s/mlspc8rvs5ey1 ... .capx?dl=0

  • ultrafop

    I can't open your capx right now but if you made the variables local you also need to make them static. With just local the variables will not save their changes.

  • anglerotate(start, end, step) Rotate angle start towards end by the angle step, all in degrees. If start is less than step degrees away from end, it returns end.

  • I guess you're looking for some kind of ease? starts slowly, then faster, and slower ... Check out sin or cos? i think they are your friends in this case.

  • ultrafop

    I can't open your capx right now but if you made the variables local you also need to make them static. With just local the variables will not save their changes.

    Thanks R0j0, I'll make the changes. I knew this would be a good opportunity to learn something new haha.

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