# How do I rotate 360 in 3 installments

Get help using Construct 2

### » Fri May 19, 2017 10:44 am

I have sprite and I want to rotate it 360 degree in three steps smoothly
I have 2 variables "Step" & "Rotate"

on left click Add 1 to "Step"
when "Step" > 3 set "Step" to 0

When "Step" =1
> every tick add 1 to "rotate" variable
when "rotate" > 120 then set rotate to 120
When "Step" =2
> every tick add 1 to "rotate" variable
when "rotate" > 240 then set rotate to 240
When "Step" =3
> every tick add 1 to "rotate" variable
when "rotate" > 360 then set rotate to 0

Problem Comes when we click very fast like double click

and the same thing i want to do with right click for subtract
B
86
S
48
G
49
Posts: 717
Reputation: 35,986

### » Fri May 19, 2017 11:22 am

@luckyrawatlucky

Here's an example capx (r244)

I swapped "Rotate" for a "Rotating" boolean and worked directly with the Sprite's Angle.

Also used 60*dt instead of 1 every tick for smoother rotation

And it only changes Step on click if it's not Rotating, so there is no problem with double-click
Find all the Construct 2 games that were on Steam Greenlight here
B
41
S
11
G
7
Posts: 511
Reputation: 7,326

### » Fri May 19, 2017 11:26 am

too much calculations here
not easy to understand for me
I don't know about "clamp", "?" what does actually
and How can i speedup the rotation
its slow rotation
and what if i want to do double click
it should rotate 240 instead of 120
B
86
S
48
G
49
Posts: 717
Reputation: 35,986

### » Fri May 19, 2017 11:39 am

luckyrawatlucky wrote:too much calculations here
not easy to understand for me
I don't know about "clamp", "?" what does actually
and How can i speedup the rotation
its slow rotation
and what if i want to do double click
it should rotate 240 instead of 120

Clamp just keeps a value within a certain range. Think of it as a combination of min and max
clamp(value, min, max)

You can move the angle comparisons out of the Set Angle action into separate Sub-Event conditions if that is easier to follow. They are there to know which direction to rotate.

Rotation speed is that 60*dt part, just replace the 60 with another value or variable

If you want to allow multiple clicks or double click, just remove the inverted Is Rotating conditions from the click events
Find all the Construct 2 games that were on Steam Greenlight here
B
41
S
11
G
7
Posts: 511
Reputation: 7,326

### » Fri May 19, 2017 12:05 pm

is their any other way of doing it
because it seems very difficult for me to understand the logic
I never use symbols like you used and i did not understand what they belongs here
like "?" , " : " , " > "
last one i know its grater than symbol but how to use it here
Self.Angle > 120 ? clamp(Self.Angle - 60*dt, 120, Self.Angle) : clamp(Self.Angle + 60*dt, Self.Angle, 120)

i never did these type of calculations
and until i didn't understand anything, I didn't apply it on my project. because want learning but keep things simple
like my example
my example is working very fine but problem comes when sprite cross 360
and when reverse rotation.
B
86
S
48
G
49
Posts: 717
Reputation: 35,986

### » Fri May 19, 2017 12:17 pm

luckyrawatlucky wrote:I never use symbols like you used and i did not understand what they belongs here
like "?" , " : " , " > "
last one i know its grater than symbol but how to use it here
Self.Angle > 120 ? clamp(Self.Angle - 60*dt, 120, Self.Angle) : clamp(Self.Angle + 60*dt, Self.Angle, 120)
.

"?" is like "then"
":" is like "else"

So it's like doing:
if thisCondition then
do this
else
do that

Or putting it in event terms:

System: Compare Sprite.Angle > 120
Sprite: Set angle to clamp(Self.Angle - 60*dt, 120, Self.Angle)
Else
Sprite: Set angle to clamp(Self.Angle + 60*dt, Self.Angle, 120)

Take a look at the manual about Expressions

?: is a conditional operator, which allows you to test conditions in expressions. This is especially useful when used with the comparison operators and logical operators. It takes the form condition ? result_if_true : result_if_false
e.g. health < 0 | score < 0 ? "Game over!" : "Keep going!".
The condition counts as true if it is non-zero, and false if it is zero.
Find all the Construct 2 games that were on Steam Greenlight here
B
41
S
11
G
7
Posts: 511
Reputation: 7,326

### » Mon May 22, 2017 7:13 am

@OddConfection
I am getting 1 problem here
on startup i click right button then Step become 3 and doesn't rotate sprite
but after 1 click everything works fine
Now how we can fix this problem??
B
86
S
48
G
49
Posts: 717
Reputation: 35,986

### » Mon May 22, 2017 7:26 am

luckyrawatlucky wrote:@OddConfection
I am getting 1 problem here
on startup i click right button then Step become 3 and doesn't rotate sprite
but after 1 click everything works fine
Now how we can fix this problem??

Change the starting value of Step from 0 to 3, that should fix it.
Find all the Construct 2 games that were on Steam Greenlight here
B
41
S
11
G
7
Posts: 511
Reputation: 7,326

### » Mon May 22, 2017 11:36 am

Starting value of Step is 1
I have changed 3 with 1 and 1 with 3
now same problem coming for left click
B
86
S
48
G
49
Posts: 717
Reputation: 35,986

### » Mon May 22, 2017 11:41 am

Why are you guys making things complicated, luckyrawatlucky you can use the same event system you wrote on start, just ad an trigger every sec condition which will prevent the sprite from rotating twice on a double click or fast clicking (every 0.5 sec or 1 sec will be sufficient).
Like my work? Fallow me on social media, and see my games on the arcade.
B
8
S
5
G
9
Posts: 298
Reputation: 5,402

Next