# Negative angles

Get help using Construct 2

### » Fri Dec 06, 2013 5:54 am

CAPX: https://www.sugarsync.com/pf/D6025908_4317202_6004926

I have doors that swing open clock or counter-clockwise. So that the doors don't swing open or close indefinitely, I'm using instance variables to define their open and closed positions. (That way I can pre-rotate them on the layout and then calculate the open and closed angles from that initial angle.)

If I have one door set to an initial angle of 0 - it's closed state - I tell it to set its instance variable OpenAngle to Door.Angle-90. However, this produces a negative angle, and any further instructions I give it leaves C2 confused about what to do.

What's a good way to efficiently recalculate this angle to a positive value of 270? (Sorta like going backwards in time...for instance, going from 1 o'clock back to 12 and not some odd time like negative 2 o'clock.)

Thanks!
I'm seeking Narnia. Who wants to come with me! Aslan is on the move!
B
146
S
25
G
8
Posts: 802
Reputation: 15,448

### » Fri Dec 06, 2013 8:54 am

have you tried using the 'is clockwise from' condition?

you can invert it for anti-clockwise

using the angle related stuff in c2 should work regardless of whether the angle is negative or above 360 or whatever.
B
28
S
8
G
1
Posts: 469
Reputation: 4,683

### » Fri Dec 06, 2013 11:59 am

Yeah it should work with negative angles, but if it doesn't, he is a possible math approach:

if object.angle is less than 0: set object.angle to 360+object.angle%360
else: set object.angle to object.angle%360

I hope this is correct. I can't create negative angles by runtime, it just goes from 0 to 359 when setting self.angle-1

edit: yes works. But wouldn't it be easier to set up the opening of doors like this:

(when door should open):
if door.helper < door.openangle: add 1 to angle; add 1 to door.helper (a instance variable)

(when door should close):
if door.helper > 0: substract 1 from angle, substract 1 from door.helper

The helper variable keeps track of how many big of a swing your door already took and if its maximum swing angle is reached, it stops. same for closed.

Ofc if you want to make it framerate independant you might wanna set it up like this:
if door.helper < door.openangle: set door.helper to clamp(door.helper+60*dt,0,door.openangle)
set angle to door.startangle+door.helper

etc.mindfaQ2013-12-06 12:31:04
Visual Novel 'Engine' in 100 Events
if you ever have to choose between buying Construct 2 on scirra.com or on Steam, read this: Review
B
22
S
9
G
1
Posts: 788
Reputation: 3,788

### » Fri Dec 06, 2013 1:54 pm

Yes, in a general case, (angle + 360)%360 is nice to quickly convert angles to positive.
B
92
S
31
G
24
Posts: 3,191
Reputation: 32,739

### » Sun Dec 08, 2013 11:23 pm

Thanks, everyone.
Ironically, while I waited for a reply, I DID realize - DOH! - that there is an action to rotate objects as @keepee pointed out. Just wasn't thinking about it since I don't need it very often...yet.
Anyway, all is working now. #FamousLastWords
I'm seeking Narnia. Who wants to come with me! Aslan is on the move!
B
146
S
25
G
8
Posts: 802
Reputation: 15,448