Why can direction of self be over 360?

froz

  • Posts: 250
Hi there,

the subject says it all. I don't understand why the direction of an actor is not like any other angle, told with a number of degrees from -180 to 180, but instead it appears in can be any number. For example if I turn my actor in game clockwise, after reaching 180 it won't switch to -179, but it will be 181. Later it can be over 360 and more. It's really frustrating and I wish I would notice it earlier. Any reason why it works like this?

Is there any better workaround to get direction degrees in range of (almost) -180 to 180 then get reminder of direction/360 and check if it's more then 180, if it is, decrement it by 360?

Thanks for help.

rob1221

  • *
  • Posts: 9472
I think internally the number is converted, so -180, 180, and 540 are all the same direction, left.

froz

  • Posts: 250
Well, maybe, but when I get direction (to compare it to other angles) it isn't converted. I was really suprised to see this.

rob1221

  • *
  • Posts: 9472
Oh, I see.  If you wrap the direction in "as degrees" does that do anything?  If not you may have to continue the workaround you mentioned.  A custom block would make it easier to use.

froz

  • Posts: 250
Thanks for the hint, I'll check that later.

froz

  • Posts: 250
Nope, "as degrees" seems to simply multiply it (like when converting from radians to degrees).

coleislazy

  • *
  • Posts: 2607
When you need to get your angle, do something like "if desiredAngle = (direction of self) mod 360". Mod (modulo) is just the remainder after division. If you divide by 360 and get the remainder, you'll always have a number between 0 and 359.

Hectate

  • *
  • Posts: 4645
It can be greater than 360 so you can see how many rotations something has done (imagine counting flips in something like a skateboarding game).
:
:
Patience is a Virtue,
But Haste is my Life.
Proud member of the League of Idiotic Stencylers; doing things in Stencyl that probably shouldn't be done.

froz

  • Posts: 250
@coleislazy - well, yeah, that's what I wrote in the first post :). Stencyl has a block for that (remainder of _).
I was just thinking if I missed a simpler way to transform it to -180 - 180 range. Anyway, thanks for help, I have managed to fix my code.

@Hectate: yes, I imagine now that it can be used like this, but for me it was not intuitive. I thought one would have to measure flips manually, but direction would always be just direction, like in real world. Normally you can't have direction of 500 degrees to something, it would always be 140 (or 220).

Nevermind though, I wouldn't even write about it if I wasn't so upset after wasting several hours because I didn't know about it.