0 Favourites

# Problem when angle goes from +180 to -180

• 11 posts
• Hi!

http://dl.dropbox.com/u/53374990/Rotarything.capx

*Edit* cap no longer rotates due to changes in r75. Recreating the "rotate layer.." events fixes it.

So holding down Q or E (or the numpad buttons) changes the layout angle target.. and the actual layout then follows it.. (These variables are GravTarget and GravCurrent)

This works fine if you allow the target angle to go above 180, but for other reasons, I need the angle to stay in the confines of 180 to -180

*but* when the target passes over the +180 to -180 threshold at the very top, the actual angle spins back, and takes the long way around... instead of over the threshold..

Am I stupid? I feel like this should have a simple solution but I just can't think

• The two events that check the angles are the problem. You telling the angle to change to target-360 when it reaches a certain angle. It then rushes over to that angle.   when you reach -180 it flips to +180 which is the other direction...

To keep it within -180 and +180 you would have to have an event check curentangle within 180 & -180 then disable left angle movement or right angle movement.

Something like that..   Dont have time to change capx right now.

• Sorry, I edited the original post to be a bit clearer...

Did you see the comment in the events? I know this is what is causing it.

When I said "in the confines of 180 to -180", i just meant the value of the target..

The problem is I want it to be able to go *past* the 180-180 threshold, instead of spinning all the way around, or simply stopping rotation.

• This problem is in my game also. Im not sure if it can be solved.. Its gotta be to do with the math. If the angle is 360 and we need to get back to 0 then 0 is a positive number so it goes backwards, Maybe we need to set it to -0 ... hmm try that :) -- ps i have no idea what im talking about

• Some solution

Tbh I'm not that maths savy. So there will surely be better implementations proposed.

This does the trick more or less, but is not perfectly seamless in the rotation.

Anyway, hope it gives you some clues.

• The problem is I want it to be able to go *past* the 180-180 threshold, instead of spinning all the way around, or simply stopping rotation.

If you want to be able to have an angle like 540 degrees, try using an instance variable and setting the angle to the instance variable. Construct 2 never lets angles go outside the -180/180 range.

• What I did on someone's capx

<img src="http://dl.dropbox.com/u/23551572/C2/angleLerping.png" border="0" />

If I remember I was smooth rotating the layout to align with the rotation of the Player (this Player.Angle)

I don't think you need all these %360 though... I was just being too carefull

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

Construct 3 users don't see these ads
• Woo I actually came here to say I solved it, (although it accelerates smooth and then stops abruptly)

But I guess I can have both types of movement :D

Thanks guys! Yanns events worked.. although kyat had something very similar.

Now I need to get my head around exactly what I just input here..

thanks again.

• Yann, IIRC Construct 2 automatically does a % 180 on any angle passed to 'Set angle' (not 360, since % 180 clamps to -180 to 180).

• %180 ?... isn't that weird?

181 is the same as -179

but 181%180 = 1 isn't it?

Anyway yeah as I said I probably put too much %360

because at the time, the interpolation kept bugging and I was over cautious (of course the issue were elswhere)

• Oops, yeah I meant % 360, with an extra if over 180, subtract 360.

• 11 posts