Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » Touching Clones
- Splodgey
-
Scratcher
100+ posts
Touching Clones
Is there a way of detecting if a clone is touching another clone, and which clone it is touching?
I know you could use the touching colour block, but that doesn't detect which clone it is touching…
I know you could use the touching colour block, but that doesn't detect which clone it is touching…
- Splodgey
-
Scratcher
100+ posts
Touching Clones
I've come up with one method:
when I start as a cloneIs there a more efficient way of doing this?
change [NextID v] by (1)
set [id v] to (NextID)
set [color v] effect to ((id) * (10))
check for touch
define check for touch
if<touching color [#FF0000]?>
set [touchingID v] to [1]
end
if<touching color [#DD6600]?>
set [touchingID v] to [2]
end
if<touching color [#CC8800]?> //continuing this as many times as you have clones
set [touchingID v] to [3]
Last edited by Splodgey (Sept. 17, 2013 11:53:18)
- Psiborg
-
Scratcher
500+ posts
Touching Clones
It depends what exactly you are trying to achieve as to how you might solve it. One way is to record the positions of all the clones in a list, then when your “if touching” test triggers, you could use the coordinates in the list to ascertain which clone is the closest and hence the one that is touching.
There are other ways of doing it, but the best way will depend on what your project is attempting to do.
There are other ways of doing it, but the best way will depend on what your project is attempting to do.
- xlk
-
Scratcher
100+ posts
Touching Clones
you can store x/y positions of all clones in a list, and use hitboxes….
- Splodgey
-
Scratcher
100+ posts
Touching Clones
The problem with storing x and y positions, is it ends up appearing incredibly laggy with only 2 clones, even in turbo mode….
It has to check if anything is touching it constantly, while moving, so it's constantly updating the list, and constantly checking it…
It has to check if anything is touching it constantly, while moving, so it's constantly updating the list, and constantly checking it…
you can store x/y positions of all clones in a list, and use hitboxes….Psiborg just said the same thing…
- Psiborg
-
Scratcher
500+ posts
Touching Clones
The problem with storing x and y positions, is it ends up appearing incredibly laggy with only 2 clones, even in turbo mode….It really shouldn't lag, I've done this with loads of clones before. I imagine there are some optimisations that could be made in your code to get it working.
It has to check if anything is touching it constantly, while moving, so it's constantly updating the list, and constantly checking it…
- chai112
-
Scratcher
33 posts
Touching Clones
The problem with storing x and y positions, is it ends up appearing incredibly laggy with only 2 clones, even in turbo mode….
It has to check if anything is touching it constantly, while moving, so it's constantly updating the list, and constantly checking it…you can store x/y positions of all clones in a list, and use hitboxes….Psiborg just said the same thing…
Challenge Accepted. I'll try to make a project like that!
please wish me luck! 
Last edited by chai112 (Sept. 17, 2013 16:06:50)
- Splodgey
-
Scratcher
100+ posts
Touching Clones
It's laggy even with one clone, and I can't think of or see any optimisations I could make… All they do is move at a speed based on item (id) of a list, and randomly turn, and adding the x position and y position lists causes it to lag horribly…The problem with storing x and y positions, is it ends up appearing incredibly laggy with only 2 clones, even in turbo mode….It really shouldn't lag, I've done this with loads of clones before. I imagine there are some optimisations that could be made in your code to get it working.
It has to check if anything is touching it constantly, while moving, so it's constantly updating the list, and constantly checking it…
- Psiborg
-
Scratcher
500+ posts
Touching Clones
It's laggy even with one clone, and I can't think of or see any optimisations I could make… All they do is move at a speed based on item (id) of a list, and randomly turn, and adding the x position and y position lists causes it to lag horribly…Both of the projects in my sig store the x and y coordinates of clones in lists and this doesn't present any performance issue. Perhaps you can share your project and we can see what the issue is?
- happyland440
-
Scratcher
1000+ posts
Touching Clones
when I start as a clonechange NextID by 1set id to NextIDset color effect to id * 10check for touchI just want a simple way of doing this.
definecheck for touchif touching color ?set touchingID to 1if touching color ?set touchingID to 2if touching color ?continuing this as many times as you have clonesset touchingID to 3
Is there a more efficient way of doing th
- vidarfw02
-
Scratcher
100+ posts
Touching Clones
http://scratch.mit.edu/projects/23988940/
Its a bit messy. Im sure somebody can improve on it…its getting late anyways
Its a bit messy. Im sure somebody can improve on it…its getting late anyways

Last edited by vidarfw02 (July 23, 2014 10:32:37)
- QuantumSingularity
-
Scratcher
1000+ posts
Touching Clones
Uhhhh…. I think that this is a duplicate: https://scratch.mit.edu/discuss/topic/14349/?page=1
- QuantumSingularity
-
Scratcher
1000+ posts
Touching Clones
Uhhhh…. I think that this is a duplicate: https://scratch.mit.edu/discuss/topic/14349/?page=1Shoot, necropost, I had multiple tabs open. SORRY!
- Harakou
-
Scratcher
1000+ posts
Touching Clones
o-oUhhhh…. I think that this is a duplicate: https://scratch.mit.edu/discuss/topic/14349/?page=1Shoot, necropost, I had multiple tabs open. SORRY!
- Discussion Forums
- » Help with Scripts
-
» Touching Clones