Negative angles

0 favourites
  • 5 posts
  • 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!

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

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

  • Yes, in a general case, (angle + 360)%360 is nice to quickly convert angles to positive.

  • Try Construct 3

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

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

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)