If I use a "glide 1 secs to random position" is there a way to detect if they are moving on the y axis or the x axis so it can change costume?

id: 749664

category: Help with Scripts

posts: 10

so I really need help because I want the sprite to change costume that is the character looking to the direction it is moving.
Pidjin Pidjin loading

oogabooga21748936 wrote:

so I really need help because I want the sprite to change costume that is the character looking to the direction it is moving.
I don't understand, could you give more context?
store its position in variables before you glide, then in a separate script (for the sprite will not continue with the script it's gliding in until it's done gliding) set both values to (stored x - current x) and likewise for y. then compare the absolute values in an if else to see which axis the sprite is moving more in (do all this in a run without screen refresh custom block).

the sprite will almost never move in just one axis.
Pidjin Pidjin loading
Maybe it can be forced to move in just one axis only. Here is an example script:

when green flag clicked
if <(pick random (1) to (2)) = [1]> then
set [my variable v] to (pick random (-240) to (240)) // x-axis
if <(my variable) < (x position)> then // moving left
switch costume to [left v]
else // moving right
switch costume to [right v]
end
glide (1) secs to x: (my variable) y: (y position)
else
set [my variable v] to (pick random (-180) to (180)) // y-axis
if <(my variable) < (y position)> then // moving down
switch costume to [down v]
else // moving up
switch costume to [up v]
end
glide (1) secs to x: (x position) y: (my variable)
end

Catscratcher07 wrote:

store its position in variables before you glide, then in a separate script (for the sprite will not continue with the script it's gliding in until it's done gliding) set both values to (stored x - current x) and likewise for y. then compare the absolute values in an if else to see which axis the sprite is moving more in (do all this in a run without screen refresh custom block).

the sprite will almost never move in just one axis.

but what i'm trying to do is which one its moving on

Pidjin wrote:

Maybe it can be forced to move in just one axis only. Here is an example script:

when green flag clicked
if <(pick random (1) to (2)) = [1]> then
set [my variable v] to (pick random (-240) to (240)) // x-axis
if <(my variable) < (x position)> then // moving left
switch costume to [left v]
else // moving right
switch costume to [right v]
end
glide (1) secs to x: (my variable) y: (y position)
else
set [my variable v] to (pick random (-180) to (180)) // y-axis
if <(my variable) < (y position)> then // moving down
switch costume to [down v]
else // moving up
switch costume to [up v]
end
glide (1) secs to x: (x position) y: (my variable)
end
i'm confused but i'll try
Simple.

forever
set [last x v] to [(x position)]
wait (0) secs
if <not <[(x position)] = [(last x)]>> then
...
end

Pidjin wrote:

Maybe it can be forced to move in just one axis only. Here is an example script:

when green flag clicked
if <(pick random (1) to (2)) = [1]> then
set [my variable v] to (pick random (-240) to (240)) // x-axis
if <(my variable) < (x position)> then // moving left
switch costume to [left v]
else // moving right
switch costume to [right v]
end
glide (1) secs to x: (my variable) y: (y position)
else
set [my variable v] to (pick random (-180) to (180)) // y-axis
if <(my variable) < (y position)> then // moving down
switch costume to [down v]
else // moving up
switch costume to [up v]
end
glide (1) secs to x: (x position) y: (my variable)
end
IT WORKED THANK YOU SO MUCH!!!
now how would you do it with someone following that sprite?
speakerset speakerset loading
99% of the time, you will be moving on more than one axis, but it is possible to create a generalised script