Rotation 0-359 only?

HappyKat78HappyKat78 Member, BASIC Posts: 173

Hi All,

I'm trying to get the rotation of an actor between 0 and 359 degrees. However, if the actor rotates past 359 degrees its rotation keeps going up i.e. 360, 361, 362 etc. but I want it to go back to 0. Is there a formula I can use to always get the rotation of an actor between 0 and 359 degrees?

Thanks,

HK

Comments

  • SLOCM3ZSLOCM3Z Member Posts: 797

    Constrain self.rotation to self.rotation%360 should would work.

  • SocksSocks London, UK.Member Posts: 12,822

    @HappyKat78 said:
    I'm trying to get the rotation of an actor between 0 and 359 degrees.

    You are missing out a whole degree !

  • RabidParrotRabidParrot Formally RabidParrot. Member Posts: 956
    edited November 2015

    Ah, I've seen this far too many times. I fixed the issue with 2 rules.

    When rotation is greater than 359 change self rotation to 0.

    When rotation is less than 1 change attribute self rotation to 360.

  • HappyKat78HappyKat78 Member, BASIC Posts: 173
    edited November 2015

    Thanks all!

    @Socks I thought for some reason 360 was the same as 0 hence it only went to 359, but maybe I'm wrong.

  • The_Gamesalad_GuruThe_Gamesalad_Guru Member Posts: 9,922

    @HappyKat78 said:
    Thanks all!

    @Socks I thought for some reason 360 was the same as 0 hence it only went to 359, but maybe I'm wrong.

    No you were right.

  • SocksSocks London, UK.Member Posts: 12,822
    edited November 2015

    @HappyKat78 said:
    Thanks all!

    @Socks I thought for some reason 360 was the same as 0 hence it only went to 359, but maybe I'm wrong.

    You are right, 360° is the same as 0° . . . . but . . . . 359° is 1° short of 0° !

    So you are leaving out the area from 359° to 360° (degrees aren't quantized to 1° increments - or any other arbitrary value).

    Representing a circle as 0° to 359° is the same as representing a circle as 1° to 360° (where the range from 0° to 1° is missing).

    If you really wanted to best represent the full range of angles in a circle you would need to find out to how many decimal places GS measures a circle, let's for the sake of argument say it's 8 decimal places - and then make your range 0-359.99999999 - but in practical terms you may as well make your range 0-360° as it will never be more than 1/100,000,000th of a degree out ! Whereas 0-359° will be as much as 1° out.

    Hope that makes sense !!

  • SocksSocks London, UK.Member Posts: 12,822
    edited November 2015

    @RabidParrot said:
    Ah, I've seen this far too many times. I fixed the issue with 2 rules.

    When rotation is greater than 359 change self rotation to 0.

    This would mean 359.1° would suddenly jump to 0/360° !

    @RabidParrot said:
    When rotation is less than 1 change attribute self rotation to 360.

    Same deal here, you will get a little glitch when the angle drops below 1°, as it misses out the whole 0-1° range.

    As @jdlcrater says, constraining the angle to angle%360 will keep it in the 0-360° range.

    [/CircleNerdWars]

  • The_Gamesalad_GuruThe_Gamesalad_Guru Member Posts: 9,922

    What @socks says is also true. I believe there is also a way to address the circle in radians which is how box2d processes it.

  • FrantoFranto Member Posts: 779
    edited November 2015

    GS is able to read angles in increments of 360 as well. For example, if you set an interpolate behavior for an actor's angle to 1800, it will rotate the actor 5 times{for whatever duration you set, 0.5 seconds will give you a spin every 0.1 seconds}. 720 would be 2 rotations, 1080 is 3, and so on. It's a good way to control a rotation more precisely, without have to use an attribute or rule condition to determine when the angle has to reset back to 0.

  • RabidParrotRabidParrot Formally RabidParrot. Member Posts: 956
    edited November 2015

    When rotation is >=361 change rotation to 0

    When rotation is <=-1 change rotation to 360

    Or you could constrain like jdl stated.

  • SocksSocks London, UK.Member Posts: 12,822

    @RabidParrot said:
    When rotation is >=361 change rotation to 0

    This will let the rotation reach 361 . . . at which point it will snap backwards to 360/0 !

    @RabidParrot said:
    When rotation is <=-1 change rotation to 360

    Same deal here !!

    [/CircleNerdWars]

  • RabidParrotRabidParrot Formally RabidParrot. Member Posts: 956

    @Socks said:

    @RabidParrot said:
    When rotation is >=361 change rotation to 0

    This will let the rotation reach 361 . . . at which point it will snap backwards to 360/0 !

    @RabidParrot said:
    When rotation is <=-1 change rotation to 360

    Same deal here !!

    [/CircleNerdWars]

    Errrrmagersh!

  • RabidParrotRabidParrot Formally RabidParrot. Member Posts: 956

    I concede.

  • SocksSocks London, UK.Member Posts: 12,822

    @RabidParrot said:
    I concede.

    Lol ! :D :p

Sign In or Register to comment.