Convert Number to Angle?

This forum is currently in read-only mode.
From the Asset Store
Jump on numbers in the proper order and reach the sun!
  • I'm in need of help...

    How would I convert a number (i.e. 1000) to whatever angle that would be?

  • 1000%360

  • Yep, you probably don't need the number of complete rotations that 1000/ 360 would give you. (2)

    % or modulus gives you the remainder of 1000/360.(.77777777)

    But keep in mind that's in addition to current angle.

    If you do need the number of rotations, and a method to implement them without the 0/360 reset, Lucid's math plug with anglerp() will also work nice.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • That sort of works...

    If I set an object's angle to 1000, I need to know what angle (0-360) that would be.

    So if the number happens to be 450.33 then the object would be pointing at 90.33 degrees.

    This way gives me an approximate but only in whole numbers.

  • Here's another way : (1000/360 - round down(1000/360)) * 360 witch equals 280 degree. To get a whole number just round all that : round((1000/360 - round down(1000/360)) * 360)

    Hope this helps.

  • That sort of works...

    If I set an object's angle to 1000, I need to know what angle (0-360) that would be.

    So if the number happens to be 450.33 then the object would be pointing at 90.33 degrees.

    This way gives me an approximate but only in whole numbers.

    Not sure what you mean.

    360 degrees is one revolution, so 0.25 of one revolution would be?

  • Maybe I'm not being clear...

    If you tell a sprite "set angle" to 450.33, it would be pointing at 90.33.

    How could I get 90.33 without resorting to using a sprite?

  • your.angle % 360 should do that.

  • But that only works on integers not floats.

    How could I do this but with floats?

    Also... with negative numbers if you did -450%360 it gives you -90 but if you set a sprite to -450%360 and retrieve the angle it is at you get 270 which is what I want

  • n-360*floor(n/360) will do the same thing as "%" but preserve floating point numbers.

    If you want only a positive angle as a answer:

    n-360*floor(n/360) +360*(n<0)

  • Oh wow, was using windows calc, but I see now that Construct wont accept floats with %.

    n-360*floor(n/360) will do the same thing as "%" but preserve floating point numbers.

    If you want only a positive angle as a answer:

    n-360*floor(n/360) +360*(n<0)

    heh figured Rojo, or one of the other brains would figure it out.

    Guess you could also use int() there too.

    450.33-360*int(450.33/360)

  • Thank you!

    That does it.

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