Discuss Scratch

annieran7
Scratcher
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

Last edited by annieran7 (Aug. 11, 2021 03:11:56)

Yusei-Fudo
Scratcher
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
Scratcher
100+ posts

Left, right finder

Yusei-Fudo wrote:

if <(x position)>([x position] of (sprite2 v))> then 
to the right
else
to the left//(most likely)
end
this would detect sprites that are super far away, which isn't really how driving works
annieran7
Scratcher
9 posts

Left, right finder

Yusei-Fudo wrote:

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
Scratcher
1000+ posts

Left, right finder

annieran7 wrote:

But what if the sprite rotates so the left and right change for that sprite?
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.


annieran7
Scratcher
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
Scratcher
9 posts

Left, right finder

The_Imaginarium wrote:

annieran7 wrote:

But what if the sprite rotates so the left and right change for that sprite?
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.



This is confusing to me but I think I'm starting to figure it out
The_Imaginarium
Scratcher
1000+ posts

Left, right finder

annieran7 wrote:

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?
That's a good solution!
The_Imaginarium
Scratcher
1000+ posts

Left, right finder

annieran7
Scratcher
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
Scratcher
9 posts

Left, right finder

The_Imaginarium wrote:

annieran7 wrote:

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?
That's a good solution!

Thanks!

Powered by DjangoBB