Discuss Scratch

franciscomagic
Scratcher
37 posts

How can we make a "point towards closest clone of myself" block?

Hello,

Does somebody know about how to make a
point towards closest clone of [myself v] :: motion
block?

I need it for parcticles to interact in a gravity simulator.

Discuss below.
awesome-llama
Scratcher
1000+ posts

How can we make a "point towards closest clone of myself" block?

It's often not worth trying to simulate with clones, they are too limiting.
You'd be better off handling everything within lists and either use clones exclusively for displaying things on screen or switch to rendering with pen or pen stamps.
Storing the particles as items of a list (or multiple lists) means you can simply iterate over the items to perform the needed operations. For example, to point towards the nearest particle, iterate over the items, calculate the distance to them, and finally point towards the one that was found to be the closest.

franciscomagic
Scratcher
37 posts

How can we make a "point towards closest clone of myself" block?

awesome-llama wrote:

It's often not worth trying to simulate with clones, they are too limiting.
You'd be better off handling everything within lists and either use clones exclusively for displaying things on screen or switch to rendering with pen or pen stamps.
Storing the particles as items of a list (or multiple lists) means you can simply iterate over the items to perform the needed operations. For example, to point towards the nearest particle, iterate over the items, calculate the distance to them, and finally point towards the one that was found to be the closest.

I understand but for that we needed to have a
Point towards x()y() :: motion
block.

Last edited by franciscomagic (Sept. 10, 2023 13:58:25)

S_w0Lf
Scratcher
27 posts

How can we make a "point towards closest clone of myself" block?

define Point Toward (x) (y)
point in direction ((90) - ([atan v] of (((y) - (y position)) /((x) - (x position)))
if <(x) < (x position)> then
point in direction ((direction) + (180))
end

Last edited by S_w0Lf (Sept. 11, 2023 08:19:34)

WestandRosy
Scratcher
51 posts

How can we make a "point towards closest clone of myself" block?

have every clone put their X and Y coords into 2 global lists based on id (e.g. clone with an id of 4 replaces the 4th slot of the X and Y coord lists)

then, use a distance formula to filter between the x and y coords in order to find the smallest one

after it does that, then use the script s_w0lf put in

there probably are better ways to do this, but this is the first way I could think of. I hope this helps!
WindowsMeRules2000
Scratcher
500+ posts

How can we make a "point towards closest clone of myself" block?

I devised a solution to this in https://scratch.mit.edu/projects/891822508/. It may not be fast, but it works!

Powered by DjangoBB