Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » Tracking x and y coordinates of a clone
- erodin_spooder
-
New Scratcher
1 post
Tracking x and y coordinates of a clone
I have a sprite that is supposed to move in a circular orbit and spin at the same time. I thought of making the sprite at the centre of the orbit rotate and create clones, with the orbiting sprite going to the location of the clones. I am stuck here and need to find the coordinates of the clones to move the orbiting sprite to them.
- PeterB8
-
Scratcher
2 posts
Tracking x and y coordinates of a clone
create a sprite-only variable called like “id” or something so you can keep track of each clone, then create lists for x and y coordinates and have said clone constantly replace the id position for said x and y lists
hope this helps
when green flag clicked
set [ id] to [0]
repeat (x)
change [ id] by (1)
create clone of [ myself]
end
when I start as a clone
forever
replace item ( id) of [list x] with (x position)
replace item ( id) of [list y] with (y position)
end
hope this helps

- MasterofTheBrick
-
Scratcher
1000+ posts
Tracking x and y coordinates of a clone
Differentiate between all the clones which have been created. The commonly implemented method would be to assign a value to each clone using local variables (a variable which can only be accessed by 1 sprite).
You will also require the use of global lists (a list which is available to all sprites) to store and keep track of multiple pieces of data at once, or in this case, the positions of each clone. This can be achieved by using list items to track the respective x and y coordinates of a specific clone. As an example:
Since list items have values assigned to them (list item 1, 2, 3), we can make use of these values and match them to the clones with matching IDs. Clone with ID variable = 1 would keep track of the first and second list items, clone with id = 3 would keep track of the third and fourth, and so on. The ID variable is increased by intervals of 2 as each clone will be constantly assigned to two list items (the x and y positions), so extracting the xy coordinates of a specific clone can be done by inputting its ID into a list reporter.
You will also require the use of global lists (a list which is available to all sprites) to store and keep track of multiple pieces of data at once, or in this case, the positions of each clone. This can be achieved by using list items to track the respective x and y coordinates of a specific clone. As an example:
set [id v] to [-1] //a necessary step before creating the first clone
create clone of [myself v]
change [id v] by (2)
add (x position) to [clone coord v]
add (y position) to [clone coord v]//these 3 functions should always be carried out when a clone is created
when I start as a clone
forever
go to x: (item (id) of [clone coord v] :: list) y: (item ((id) + (1)) of [clone coord v] :: list)
end
Since list items have values assigned to them (list item 1, 2, 3), we can make use of these values and match them to the clones with matching IDs. Clone with ID variable = 1 would keep track of the first and second list items, clone with id = 3 would keep track of the third and fourth, and so on. The ID variable is increased by intervals of 2 as each clone will be constantly assigned to two list items (the x and y positions), so extracting the xy coordinates of a specific clone can be done by inputting its ID into a list reporter.
Last edited by MasterofTheBrick (Nov. 3, 2023 12:04:36)
- -L00P-
-
New Scratcher
23 posts
Tracking x and y coordinates of a clone
I have a sprite that is supposed to move in a circular orbit and spin at the same time. I thought of making the sprite at the centre of the orbit rotate and create clones, with the orbiting sprite going to the location of the clones. I am stuck here and need to find the coordinates of the clones to move the orbiting sprite to them.
If you are using the clones just to define the orbit movement, I recommend using another method.
You can make use of trigonometry to define a perfect circular movement.
- helloboop
-
Scratcher
2 posts
Tracking x and y coordinates of a clone
im making a btd game, where i clone both the dart and the bloon. I want the dart to be able to pop the bloon (Either by predicting where the bloon goes, or firing at closest entity.) how do i do that?
- Discussion Forums
- » Help with Scripts
-
» Tracking x and y coordinates of a clone




