How do I measure the distance from an angle?

  • I'm making a game where you're a bird gliding about, and you accelerate faster when you're facing downwards (angle:90) and you decelerate when you're closer to facing upwards (angle:270). I'm trying to base acceleration off of angle, but I can't account for the fact that angles wrap around from 360 back to 0. Is there a way to measure angle distance? I.E. the distance from angle 270 and 0 being 90?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • There are a few expressions related to angles:

    angle(x1, y1, x2, y2) Calculate angle between two points

    anglelerp(a, b, x) Linearly interpolate the angle a to b by x. Unlike the standard lerp, this takes in to account the cyclical nature of angles.

    anglediff(a1, a2) Return the smallest difference between two angles

    anglerotate(start, end, step) Rotate angle start towards end by the angle step, all in degrees. If start is less than step degrees away from end, it returns end.

    You're probably looking for anglediff, although you should know that it always returns positive result. I.e. anglediff(10,50) returns 40, and anglediff(50,10) also returns 40 (not -40).

    Also these system events may be useful: "Is between angles", "Is within angle", "Is clockwise from"

  • Thank you, this works great.

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