Discuss Scratch

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?
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.

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.
123opou
Scratcher
37 posts

Help with direction changing

need help with animating text
123opou
Scratcher
37 posts

Help with direction changing

[ i like trains! v]
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…

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

123opou wrote:

need help with animating text

123opou wrote:

[ i like trains! v]
Please don't spam.

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

123opou wrote:

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

asivi wrote:

???
point in direction ((direction) - (180))
Thanks
Freopt
Scratcher
23 posts

Help with direction changing

deenfoxx wrote:

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.
Thanks

Last edited by Freopt (March 24, 2017 17:58:10)

Freopt
Scratcher
23 posts

Help with direction changing

deck26 wrote:

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.
Thanks
deenfoxx
Scratcher
100+ posts

Help with direction changing

No problem. Glad we could help.
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

KamPavlov wrote:

is there a way to make the direction 0 to 360

Don’t necro post
KamPavlov
Scratcher
2 posts

Help with direction changing

?
huboojoe
Scratcher
100+ posts

Help with direction changing

KamPavlov wrote:

?
make your own topic instead of necroposting

Powered by DjangoBB