Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » determining a sprite's direction of movement
- _Awesome_Unicorn_
-
New Scratcher
15 posts
determining a sprite's direction of movement
I have variables tracking the x and y velocity of my sprite. I tried using the atan function to find the direction of motion but was unsuccessful. Can anyone help me?
- Oumuamua
-
Scratcher
1000+ posts
determining a sprite's direction of movement
I have variables tracking the x and y velocity of my sprite. I tried using the atan function to find the direction of motion but was unsuccessful. Can anyone help me?
It does mean that your Yvel is affected by gravity?
I wonder why you need to keep track of direction.
- Oumuamua
-
Scratcher
1000+ posts
determining a sprite's direction of movement

you see? *
It is the custom block that you can find in a lot of projects on Scratch.
You will need two variables to save x and y coordinates of sprite before it moves(X1 and Y1 in the CB) after the movement your sprite has a new set of coordinates(X2 and Y2) the CB calculates the direction and then you update the variables with the new coordinates… and so on. That is all.
Last edited by Oumuamua (April 21, 2020 09:29:09)
- _Awesome_Unicorn_
-
New Scratcher
15 posts
determining a sprite's direction of movement
I can't read that symbol after the 180. what kind of operation is that and how does Y1>Y2 fit in there?
- _Awesome_Unicorn_
-
New Scratcher
15 posts
determining a sprite's direction of movement
to get direction of movement to match the sprite's direction (as regarded by Scratch) I solved it with this:
if x-velocity < 1 then movement direction = -1( arctan(x-velocity/y-velocity) +90)
else if x-velocity > 1 then movement direction = -1( arctan(x-velocity/y-velocity) -90)
if x-velocity < 1 then movement direction = -1( arctan(x-velocity/y-velocity) +90)
else if x-velocity > 1 then movement direction = -1( arctan(x-velocity/y-velocity) -90)
- Oumuamua
-
Scratcher
1000+ posts
determining a sprite's direction of movement
to get direction of movement to match the sprite's direction (as regarded by Scratch) I solved it with this:
if x-velocity < 1 then movement direction = -1( arctan(x-velocity/y-velocity) +90)
else if x-velocity > 1 then movement direction = -1( arctan(x-velocity/y-velocity) -90)
By reading the original post, your looks like a miracle

Sorry if i have not helped you at all

- Discussion Forums
- » Help with Scripts
-
» determining a sprite's direction of movement

