Is the module operator suppose to return negative values?

0 favourites
  • 3 posts
From the Asset Store
Game "Little Dino Adventure Returns" with complete Source-Code (Construct3 / .c3p) + HTML5 Exported.
  • I though of using the module operator (%) to prevent angles from going onto negative values when using angle(), but it doesn't do it, even though it works like that in any calculator calculator and other programing languages (as far as I know).

    example:

    -90 % 360 should return 270, but in Construct 3 it return -90

  • Ok, after trying it in Java script, it also returns negative values, so there is that.

    Anyways, if you are using module with angles, you can just add 360 to the moduled value if you don't want it to be negative.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • %or mod has no standard behavior across programming languages. Some, like js, will will keep the sign of the original number, and some will wrap around 0 to the positive number. Which I think would be more useful.

    Anyways since angle() gives an angle -180 to 180 you can convert it to the 0-360 range with

    (a%360+360)%360

    /// the second % is to get it back into the 0-360 range.

    Or

    A<0?360+A:A

    Alternately you could use the angle conditions or the angleDiff expression to check your angles. They can be helpful especially when you have to deal with the 0-360 seam

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