Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » Help with direction changing
- Freopt
-
Scratcher
23 posts
Help with direction changing
I'm trying to make a sprite point the opposite direction it's facing. If the first character isn't a minus then add a minus. I got that. But what about if the first character is a minus? Is there a way to delete the minus and leave the rest?
Thanks
if <not <(letter (1) of (direction)) = [-]>> then
point in direction (join [-] (direction))
else
????
end
Thanks
Last edited by Freopt (March 22, 2017 16:21:14)
- asivi
-
Scratcher
1000+ posts
Help with direction changing
???
point in direction ((direction) - (180))
- deenfoxx
-
Scratcher
100+ posts
Help with direction changing
Like asivi showed… to change to the completely opposite direction, all you have to do is subtract 180 (or add 180). It is in degree measurement so 360 degrees is one complete revolution/rotation (and wouldn't show any change at all)… Half of that is half of a revolution/rotation, hence turning completely around ( https://www.google.com/search?q=define+180 ).
P.S. It is important to note that Scratch automatically does a modulus masking on whatever value you give it… So, 90 degrees PLUS 180 degrees = 270 degrees, but Scratch saves the value -90 automatically (270 - 360). More information is on the Wiki… https://wiki.scratch.mit.edu/wiki/Direction_(value)#Directions
P.P.S. For math geeks, the actual calculation is a bit more complex than shown on the Wiki, but more like this: degrees_out = ((degrees_in MOD 180) == 0) ? 180 : ((degrees_in + 180) MOD 360) - 180). Otherwise, it would allow for -180 instead of positive 180. But, you don't have to worry about that… you just have to understand the value will always be greater than -180, less than or equal to 180.
P.S. It is important to note that Scratch automatically does a modulus masking on whatever value you give it… So, 90 degrees PLUS 180 degrees = 270 degrees, but Scratch saves the value -90 automatically (270 - 360). More information is on the Wiki… https://wiki.scratch.mit.edu/wiki/Direction_(value)#Directions
P.P.S. For math geeks, the actual calculation is a bit more complex than shown on the Wiki, but more like this: degrees_out = ((degrees_in MOD 180) == 0) ? 180 : ((degrees_in + 180) MOD 360) - 180). Otherwise, it would allow for -180 instead of positive 180. But, you don't have to worry about that… you just have to understand the value will always be greater than -180, less than or equal to 180.
Last edited by deenfoxx (March 22, 2017 16:48:16)
- deck26
-
Scratcher
1000+ posts
Help with direction changing
It depends what you mean by opposite. Usually that would mean turning 180 degrees so the only direction that your version works for is 90. Change 1 degree to -1 and you've just turned anti clockwise 2 degrees.
Scratch will cope with any numbers for direction and adjust to the range it works with. So you can point in direction 730 and it will actually point in direction 10 (subtract 2 x 360). So it doesn't matter if you have, for example, -150 and subtract 180 - Scratch won't get confused by the -330 it will add 360 to get 30 which is the opposite to -150.
I suspect you therefore just want to add or subtract 180 and it doesn't matter which you use.
Scratch will cope with any numbers for direction and adjust to the range it works with. So you can point in direction 730 and it will actually point in direction 10 (subtract 2 x 360). So it doesn't matter if you have, for example, -150 and subtract 180 - Scratch won't get confused by the -330 it will add 360 to get 30 which is the opposite to -150.
I suspect you therefore just want to add or subtract 180 and it doesn't matter which you use.
- deenfoxx
-
Scratcher
100+ posts
Help with direction changing
To add to what deck26 says, the other METHODS of turning around are not considered opposite direction, but rather reflected direction. To reflect on the horizontal, just multiply your direction by -1…
… OR subtract from zero (0) …
… they accomplish the same thing, changing the positive to negative or negative to positive.
However, to reflect on the vertical, you want to subtract the current direction from 180…
NOTE: This is completely different than the pointing in the opposite direction mentioned before, which is subtracting 180 from direction…
point in direction ((direction) * [-1])
… OR subtract from zero (0) …
point in direction ([0] - (direction))
… they accomplish the same thing, changing the positive to negative or negative to positive.
However, to reflect on the vertical, you want to subtract the current direction from 180…
point in direction ([180] - (direction))
NOTE: This is completely different than the pointing in the opposite direction mentioned before, which is subtracting 180 from direction…
point in direction ((direction) - [180])
Last edited by deenfoxx (March 22, 2017 17:04:09)
- deck26
-
Scratcher
1000+ posts
Help with direction changing
need help with animating text
Please don't spam.[ i like trains! v]
If you need help create your own topic and describe your problem. Ideally share what you have so far.
- deenfoxx
-
Scratcher
100+ posts
Help with direction changing
need help with animating text
Like deck26 said, start a new topic. That has nothing to do with this topic. Either find an existing topic that pertains to animating text or start a new topic with an appropriate title. You will notice that this topic is “Help with direction changing”.
- Freopt
-
Scratcher
23 posts
Help with direction changing
???Thankspoint in direction ((direction) - (180))
- Freopt
-
Scratcher
23 posts
Help with direction changing
Like asivi showed… to change to the completely opposite direction, all you have to do is subtract 180 (or add 180). It is in degree measurement so 360 degrees is one complete revolution/rotation (and wouldn't show any change at all)… Half of that is half of a revolution/rotation, hence turning completely around ( https://www.google.com/search?q=define+180 ).Thanks
P.S. It is important to note that Scratch automatically does a modulus masking on whatever value you give it… So, 90 degrees PLUS 180 degrees = 270 degrees, but Scratch saves the value -90 automatically (270 - 360). More information is on the Wiki… https://wiki.scratch.mit.edu/wiki/Direction_(value)#Directions
P.P.S. For math geeks, the actual calculation is a bit more complex than shown on the Wiki, but more like this: degrees_out = ((degrees_in MOD 180) == 0) ? 180 : ((degrees_in + 180) MOD 360) - 180). Otherwise, it would allow for -180 instead of positive 180. But, you don't have to worry about that… you just have to understand the value will always be greater than -180, less than or equal to 180.
Last edited by Freopt (March 24, 2017 17:58:10)
- Freopt
-
Scratcher
23 posts
Help with direction changing
It depends what you mean by opposite. Usually that would mean turning 180 degrees so the only direction that your version works for is 90. Change 1 degree to -1 and you've just turned anti clockwise 2 degrees.Thanks
Scratch will cope with any numbers for direction and adjust to the range it works with. So you can point in direction 730 and it will actually point in direction 10 (subtract 2 x 360). So it doesn't matter if you have, for example, -150 and subtract 180 - Scratch won't get confused by the -330 it will add 360 to get 30 which is the opposite to -150.
I suspect you therefore just want to add or subtract 180 and it doesn't matter which you use.
- KamPavlov
-
Scratcher
2 posts
Help with direction changing
is there a way to make the direction 0 to 360
- Speed_Runnin_Scratch
-
Scratcher
34 posts
Help with direction changing
is there a way to make the direction 0 to 360
Don’t necro post
- huboojoe
-
Scratcher
100+ posts
Help with direction changing
?make your own topic instead of necroposting
- Discussion Forums
- » Help with Scripts
-
» Help with direction changing







