Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » Left, right finder
- annieran7
-
9 posts
Left, right finder
How can you tell if a sprite is to the right or left of another sprite?
More context: I'm making a project where you can draw roads and a car will follow the but I want the car to be able to try to find the best route along the roads to find a specific location
More context: I'm making a project where you can draw roads and a car will follow the but I want the car to be able to try to find the best route along the roads to find a specific location
Last edited by annieran7 (Aug. 11, 2021 03:11:56)
- Yusei-Fudo
-
1000+ posts
Left, right finder
if <(x position)>([x position] of (sprite2 v))> then
to the right
else
to the left//(most likely)
end
- BlastikGames
-
100+ posts
Left, right finder
this would detect sprites that are super far away, which isn't really how driving worksif <(x position)>([x position] of (sprite2 v))> then
to the right
else
to the left//(most likely)
end
- annieran7
-
9 posts
Left, right finder
if <(x position)>([x position] of (sprite2 v))> then
to the right
else
to the left//(most likely)
end
But what if the sprite rotates so the left and right change for that sprite?
- The_Imaginarium
-
1000+ posts
Left, right finder
Well, by definition, left and right are one dimensional, however by detecting which side of the slope created by the angle of the first sprite the second sprite is on, that would probably work the way your thinking. But what if the sprite rotates so the left and right change for that sprite?

- annieran7
-
9 posts
Left, right finder
I think I figured it out, what if you just made a costume that's a big rectangle that covers the screen and is half red half blue and sensed which color is touching the destination?
- annieran7
-
9 posts
Left, right finder
Well, by definition, left and right are one dimensional, however by detecting which side of the slope created by the angle of the first sprite the second sprite is on, that would probably work the way your thinking. But what if the sprite rotates so the left and right change for that sprite?
This is confusing to me but I think I'm starting to figure it out
- The_Imaginarium
-
1000+ posts
Left, right finder
That's a good solution! I think I figured it out, what if you just made a costume that's a big rectangle that covers the screen and is half red half blue and sensed which color is touching the destination?
- The_Imaginarium
-
1000+ posts
Left, right finder
I made a demo: https://scratch.mit.edu/projects/559854567/
- annieran7
-
9 posts
Left, right finder
also, if there is an option to go straight the cars will take it even if they should turn. Does anyone know how to fix this?
- annieran7
-
9 posts
Left, right finder
That's a good solution! I think I figured it out, what if you just made a costume that's a big rectangle that covers the screen and is half red half blue and sensed which color is touching the destination?
Thanks!
- Discussion Forums
- » Help with Scripts
-
» Left, right finder