Rotate degrees with smooth start/stop?

Get help using Construct 2

Post » Sun Aug 21, 2016 9:33 pm

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?
B
41
S
12
G
14
Posts: 1,117
Reputation: 11,253

Post » Sun Aug 21, 2016 10:13 pm

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))
B
92
S
32
G
107
Posts: 5,274
Reputation: 69,959

Post » Mon Aug 22, 2016 2:04 pm

R0J0hound wrote: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"?
B
41
S
12
G
14
Posts: 1,117
Reputation: 11,253

Post » Mon Aug 22, 2016 8:37 pm

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?
viewtopic.php?f=147&t=152653&p=967389&hilit=accelerate+angle+anglediff#p967389
B
92
S
32
G
107
Posts: 5,274
Reputation: 69,959

Post » Tue Aug 23, 2016 1:24 am

R0J0hound wrote: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?
viewtopic.php?f=147&t=152653&p=967389&hilit=accelerate+angle+anglediff#p967389

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?
B
41
S
12
G
14
Posts: 1,117
Reputation: 11,253

Post » Tue Aug 23, 2016 2:01 am

I don't know. It could be something to try.
B
92
S
32
G
107
Posts: 5,274
Reputation: 69,959

Post » Tue Aug 23, 2016 2:21 am

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
Mistakes were made.
B
51
S
25
G
107
Posts: 1,581
Reputation: 60,458

Post » Tue Aug 23, 2016 4:30 pm

@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
B
41
S
12
G
14
Posts: 1,117
Reputation: 11,253

Post » Fri Sep 16, 2016 12:45 am

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
B
60
S
36
G
23
Posts: 342
Reputation: 17,159

Post » Fri Sep 16, 2016 6:14 am

@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.
B
92
S
32
G
107
Posts: 5,274
Reputation: 69,959

Next

Return to How do I....?

Who is online

Users browsing this forum: ultrafop and 12 guests