Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » 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?
- oogabooga21748936
- Scratcher
13 posts
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?
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
- Scratcher
3 posts
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?
I don't understand, could you give more context? 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 like pigeons
Hi! I am Pidjin. I like pigeons.
when anything happens:: hat events
do nothing [sometimes v] :: cap control
This script can move sprites without fencing (doesn't work for pen):
define go to x: (x) y: (y)
move ((1) / (0)) steps
move ((1) / (0)) steps
set x to (x)
set y to (y)
- Catscratcher07
- Scratcher
1000+ posts
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?
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.
the sprite will almost never move in just one axis.
trouble with clones? view my clone id toolbox! I also have built the bases of a tower defence game link here.
If someone on help with scripts is saying that something can't be done, they should be suspected of being a team limit grunt.
- Pidjin
- Scratcher
3 posts
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?
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
Last edited by Pidjin (March 23, 2024 14:59:18)
I like pigeons
Hi! I am Pidjin. I like pigeons.
when anything happens:: hat events
do nothing [sometimes v] :: cap control
This script can move sprites without fencing (doesn't work for pen):
define go to x: (x) y: (y)
move ((1) / (0)) steps
move ((1) / (0)) steps
set x to (x)
set y to (y)
- oogabooga21748936
- Scratcher
13 posts
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?
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
- oogabooga21748936
- Scratcher
13 posts
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?
i'm confused but i'll try 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
- Robot_Turtle10
- Scratcher
10 posts
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?
Simple.
forever
set [last x v] to [(x position)]
wait (0) secs
if <not <[(x position)] = [(last x)]>> then
...
end
Last edited by Robot_Turtle10 (March 23, 2024 16:47:34)
- oogabooga21748936
- Scratcher
13 posts
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?
IT WORKED THANK YOU SO MUCH!!! 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
- oogabooga21748936
- Scratcher
13 posts
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?
now how would you do it with someone following that sprite?
- speakerset
- Scratcher
3 posts
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?
99% of the time, you will be moving on more than one axis, but it is possible to create a generalised script
- Discussion Forums
- » Help with Scripts
- » 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?