Discuss Scratch

gametime553
Scratcher
18 posts

Point to closest clone?

How do I make it so a sprite points to the closest clone. I know how to point to certain clones using list and a dot sprite which goes to the x and y in the list and make a sprite point towards the dot making seem like it is looking at the sprite.
 

when I start as a clone
forever
wait until <(length of [xpos] :: list) = [0]>
add (x position) to [xpos]
add (y position) to [ypos]
end
And in the dot sprite
when green flag clicked
forever
wait until <(length of [xpos] :: list) > [0]>
go to x: (item # of [1] in [xpos]) y: (item # of [1] in [ypos])
delete all of [xpos]
delete all of [ypos]
end
Then the sprite that is pointing
when green flag clicked
forever
point towards [dot sprite]
end
And this points to the clone and if you change the go to item number to 2 which will choose the second
clone but I don’t know how to make it choose the closest clone. I know you can use distance of the dot
to the arrow but I don’t know how to calculate it.

Last edited by gametime553 (Aug. 28, 2026 18:15:30)

amynussey
Scratcher
1 post

Point to closest clone?

wow this really helped

Last edited by amynussey (Aug. 30, 2026 11:56:37)

CuriousDragonScratch
Scratcher
7 posts

Point to closest clone?

You can't. Clones don't have a custom “point in direction” block, so, yes. You have to store the clones' positions in a list, then either using an invisible sprite, or using this algorithm to point towards the position you'd like:
when I receive [Whatever command you'd like v]
point towards x: (item (1) of [clonepos v] :: list) y: (item (2) of [clonepos v] :: list) // Assuming that item 1 is the x pos and item 2 is the y pos
define point towards x: (x) y: (y)
point in direction (([atan v] of (((x) - (x position)) / (((y) - (y position))+(0)))::operators) + ((180) * <(y) < (y position)>)
To be honest, I actually prefer the custom block, method, as it just reduces the amount of sprites.
RicDiamond1477
Scratcher
100+ posts

Point to closest clone?

CuriousDragonScratch wrote:

You can't. Clones don't have a custom “point in direction” block, so, yes. You have to store the clones' positions in a list, then either using an invisible sprite, or using this algorithm to point towards the position you'd like:
when I receive [Whatever command you'd like v]
point towards x: (item (1) of [clonepos v] :: list) y: (item (2) of [clonepos v] :: list) // Assuming that item 1 is the x pos and item 2 is the y pos
define point towards x: (x) y: (y)
point in direction (([atan v] of (((x) - (x position)) / (((y) - (y position))+(0)))::operators) + ((180) * <(y) < (y position)>)
To be honest, I actually prefer the custom block, method, as it just reduces the amount of sprites.
This incorrect, you actually can by using Lists to store each clone's X and Y positions and using subtraction and addition to tectet which clone is closest and from there you can send a sprite to that position and have the other sprite point in that direction. (this would be in a custom block with tick refresh off)
CuriousDragonScratch
Scratcher
7 posts

Point to closest clone?

RicDiamond1477 wrote:

CuriousDragonScratch wrote:

You can't. Clones don't have a custom “point in direction” block, so, yes. You have to store the clones' positions in a list, then either using an invisible sprite, or using this algorithm to point towards the position you'd like:
when I receive [Whatever command you'd like v]
point towards x: (item (1) of [clonepos v] :: list) y: (item (2) of [clonepos v] :: list) // Assuming that item 1 is the x pos and item 2 is the y pos
define point towards x: (x) y: (y)
point in direction (([atan v] of (((x) - (x position)) / (((y) - (y position))+(0)))::operators) + ((180) * <(y) < (y position)>)
To be honest, I actually prefer the custom block, method, as it just reduces the amount of sprites.
This incorrect, you actually can by using Lists to store each clone's X and Y positions and using subtraction and addition to tectet which clone is closest and from there you can send a sprite to that position and have the other sprite point in that direction. (this would be in a custom block with tick refresh off)
Why is this incorrect? I'm pointing out a way to do this without using one extra sprite. This isn't a wrong answer.
gametime553
Scratcher
18 posts

Point to closest clone?

I am not looking for a way do remove the dot sprite, I want there to be multiple clones that move around and the pointer sprite points to the closest of all of them.
RicDiamond1477
Scratcher
100+ posts

Point to closest clone?

CuriousDragonScratch wrote:

RicDiamond1477 wrote:

CuriousDragonScratch wrote:

You can't. Clones don't have a custom “point in direction” block, so, yes. You have to store the clones' positions in a list, then either using an invisible sprite, or using this algorithm to point towards the position you'd like:
when I receive [Whatever command you'd like v]
point towards x: (item (1) of [clonepos v] :: list) y: (item (2) of [clonepos v] :: list) // Assuming that item 1 is the x pos and item 2 is the y pos
define point towards x: (x) y: (y)
point in direction (([atan v] of (((x) - (x position)) / (((y) - (y position))+(0)))::operators) + ((180) * <(y) < (y position)>)
To be honest, I actually prefer the custom block, method, as it just reduces the amount of sprites.
This incorrect, you actually can by using Lists to store each clone's X and Y positions and using subtraction and addition to tectet which clone is closest and from there you can send a sprite to that position and have the other sprite point in that direction. (this would be in a custom block with tick refresh off)
Why is this incorrect? I'm pointing out a way to do this without using one extra sprite. This isn't a wrong answer.
Sorry, I misunderstood what you were saying, to me it looked like you said there was no solution to their problem.
P-P-C-moderator
Scratcher
16 posts

Point to closest clone?

check this project out and tell me if it helps you
RicDiamond1477
Scratcher
100+ posts

Point to closest clone?

gametime553 wrote:

I am not looking for a way do remove the dot sprite, I want there to be multiple clones that move around and the pointer sprite points to the closest of all of them.
You could do this by check for each clone position, using the absolute value of the clone's position minus the player's position for both the X and Y, once you do this for each, you can find which is the closest by checking which values are the closest to 0.
gametime553
Scratcher
18 posts

Point to closest clone?

P-P-C-moderator wrote:

check this project out and tell me if it helps you

What if I want the pointer sprite’s clones (for example 5 shooters clone sprites point to the closest enemy (the clone originally pointing at) and shoot at them) to point the the closest clone to them?
RicDiamond1477
Scratcher
100+ posts

Point to closest clone?

gametime553 wrote:

P-P-C-moderator wrote:

check this project out and tell me if it helps you

What if I want the pointer sprite’s clones (for example 5 shooters clone sprites point to the closest enemy (the clone originally pointing at) and shoot at them) to point the the closest clone to them?
Do you have a specific project you could share with this? There may be a better way to optimize it than requiring an extremely large script that requires doing a lot of checks just so a clone can point at another clone.
P-P-C-moderator
Scratcher
16 posts

Point to closest clone?

gametime553 wrote:

P-P-C-moderator wrote:

check this project out and tell me if it helps you

What if I want the pointer sprite’s clones (for example 5 shooters clone sprites point to the closest enemy (the clone originally pointing at) and shoot at them) to point the the closest clone to them?


Just use the same code that loop threw the list to find the nearest point + point toward, all variable are private (for sprite only so it shouldn't cause any problem)
10goto10
Scratcher
1000+ posts

Point to closest clone?

I tried to keep some of the logic that you started with in your first post and I made this case study of how clones would target other clones using helper dots (sprites). https://scratch.mit.edu/projects/1376264182/

The clones have to take turns using the dots (sprites) so there is extra logic needed to let the distance calculations happen one at a time. I've really slowed things down by using glides and wait blocks.

Powered by DjangoBB