# How do I rotate 360 in 3 installments

0 favourites
• 11 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 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

• 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

• 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

• 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

• 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

[quote:10ylja1q]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.

• 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

[quote:2moox76v]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

[quote:2moox76v]?: 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.

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

• ## Try Construct 3

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

Construct 3 users don't see these ads
• 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.

• Starting value of Step is 1

I have changed 3 with 1 and 1 with 3

now same problem coming for left click

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

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

There's more too it than that, because it needs to go different directions based on left-clicking and right-clicking which the original code didn't account for.

The capx I created isn't that complicated, or that different to the original code, there was just some unfamiliarity with the more advanced expression operators.

Starting value of Step is 1

I have changed 3 with 1 and 1 with 3

now same problem coming for left click

Setting the initial Step value to 3 should work as that is the initial position (0 degrees) and works for me.

I've updated the capx (r244)

• 11 posts