# Problem when angle goes from +180 to -180

Get help using Construct 2

### » Thu Jan 12, 2012 7:39 pm

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

B
28
S
8
G
1
Posts: 469
Reputation: 4,683

### » Thu Jan 12, 2012 8:12 pm

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.

Zetar2012-01-12 20:14:18
B
193
S
6
G
7
Posts: 213
Reputation: 10,203

### » Thu Jan 12, 2012 8:29 pm

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.
B
28
S
8
G
1
Posts: 469
Reputation: 4,683

### » Thu Jan 12, 2012 8:35 pm

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
B
30
S
13
G
7
Posts: 740
Reputation: 8,099

### » Thu Jan 12, 2012 10:02 pm

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.
New to Construct ? Where to start

Please attach a capx to any help request or bug report !
Moderator
B
311
S
128
G
101
Posts: 7,416
Reputation: 75,228

### » Thu Jan 12, 2012 10:06 pm

[QUOTE=keepee]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.[/QUOTE]
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.
Scirra Founder
B
414
S
245
G
92
Posts: 25,206
Reputation: 200,353

### » Thu Jan 12, 2012 11:13 pm

What I did on someone's capx

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
B
71
S
22
G
14
Posts: 1,494
Reputation: 16,660

### » Fri Jan 13, 2012 12:05 am

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.
B
28
S
8
G
1
Posts: 469
Reputation: 4,683

### » Fri Jan 13, 2012 10:52 am

@Yann, IIRC Construct 2 automatically does a % 180 on any angle passed to 'Set angle' (not 360, since % 180 clamps to -180 to 180).Ashley2012-01-13 10:53:13
Scirra Founder
B
414
S
245
G
92
Posts: 25,206
Reputation: 200,353

### » Fri Jan 13, 2012 12:22 pm

@Ashley
%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)
B
71
S
22
G
14
Posts: 1,494
Reputation: 16,660

Next