Angles Help

  • I've been trying to do this for a few hours, but I can't figure it out. When I use angle(x1,y1,x2,y2) I get angles like in the left image. I'm trying to essentially rotate that 90 degrees and get angles like in the right image. Anyone know an equation to achieve that? Closest I've gotten to is (angle+270) %180

    Thanks for any help.

  • Top number on your left image should read "-90" or "270".

    I don't really understand what your problem is. If you are trying to increase the angle by 90 degrees (or rotate it 90 degrees clockwise), you can simply add 90.

    Set Sprite angle to (Sprite.angle+90)

    This might give you a result which will be greater than 360, but the system will convert it to correct angle.

    Or you can use anglerotate expression:

    endAngle=anglerotate(startAngle, startAngle+90, 90)

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • It’s done in two steps: subtract 90 from the angle to rotate it, and normalizing the angle.

    ang = any_angle-90

    ang = angle(0,0,cos(ang),sin(ang))

    A longer way to normalize an angle would be these two whiles:

    While

    ang > 180

    —- subtract 360 from ang

    While

    ang < -180

    —- add 360 to ang

  • ang = any_angle-90

    ang = angle(0,0,cos(ang),sin(ang))

    That works perfectly, thanks!

    dop2000 I'm converting the angle to animation frames for aiming. I'm dividing the angle by 10 so angle 0 aims down and 18 aims up. From your equation, adding 90 to the angle doesn't work because on the left side, it jumps from -90 to 270. Thanks for the help though.

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