Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » Having a clone target another clone
- facepwn64
-
17 posts
Having a clone target another clone
is this possible? If so, can you tell me how?
- drmcw
-
1000+ posts
Having a clone target another clone
Yes, search for tower defense games. They typically want to target the nearest clone and use either lists or broadcasts to achieve that.
- ianrocks
-
47 posts
Having a clone target another clone
Yeah, many tower defense games basically have a whole bunch clones that each store their x and y positions in a list. The clone that is supposed to target another will go through the list and test the distance to each other clone using the distance formula (sqrt((x2-x1)^2+(y2-y1)^2)), and if one is closer than another, it saves the item number of that clone's coordinates, so that once it has gone through the entire list, it knows which clone is closest. That is the targeting system.
If you are looking for a script that lets a clone point towards another clone, here's what you can do:
Take the coordinates of the first clone (x1,y1) and the target clone (x2,y2).
Hope this helps!
If you are looking for a script that lets a clone point towards another clone, here's what you can do:
Take the coordinates of the first clone (x1,y1) and the target clone (x2,y2).
if <(x2) > (x1)> thenClone.direction is the direction the first clone would have to point to be pointing toward the target clone.
set [clone.direction v] to ((90) - ([atan] of (((y2) - (y1)) / ((x2) - (x1)))))
else
set [clone.direction v] to ((-90) - ([atan] of (((y2) - (y1)) / ((x2) - (x1)))))
end
Hope this helps!

- Discussion Forums
- » Help with Scripts
-
» Having a clone target another clone