Discuss Scratch

jibanyan_boi
Scratcher
40 posts

How to detect touching a clone :/

when green flag clicked
forever
if <touching (clone[1]of[sprite1 v] :: sensing) ?> then

end
end
Or something like that
deck26
Scratcher
1000+ posts

How to detect touching a clone :/

The touching sprite block works with clones as well but you can't tell whether it is the sprite or a clone (or identify the clone). To do that you'd perhaps be better having a list and get each clone to detect if it is touching the sprite and set its list item (use a cloneID system) to 0 or 1 accordingly. Then the sprite can tell from the list which clones it is touching.
jibanyan_boi
Scratcher
40 posts

How to detect touching a clone :/

deck26 wrote:

The touching sprite block works with clones as well but you can't tell whether it is the sprite or a clone (or identify the clone). To do that you'd perhaps be better having a list and get each clone to detect if it is touching the sprite and set its list item (use a cloneID system) to 0 or 1 accordingly. Then the sprite can tell from the list which clones it is touching.
Could you be able to show me an example please
Oumuamua
Scratcher
1000+ posts

How to detect touching a clone :/

https://scratch.mit.edu/projects/759149974/ quite simple, i think you can follow the flow and get the point
ccarrster
Scratcher
12 posts

How to detect touching a clone :/

A bit of a trick in scratch.
Make a sprite - lets call it A.
Make a second sprite - call it B.
A is the one with clones.
What you do is go to b.
Add a <Touching A> tag.
Then you copy that tag to sprite A.

Normally you can not select <Touching Self>.

So clone 1 would be touching clone 5 and clone 5 would be touching clone 1, so you would likely be running the same detection script twice.
jibanyan_boi
Scratcher
40 posts

How to detect touching a clone :/

ccarrster wrote:

A bit of a trick in scratch.
Make a sprite - lets call it A.
Make a second sprite - call it B.
A is the one with clones.
What you do is go to b.
Add a <Touching A> tag.
Then you copy that tag to sprite A.

Normally you can not select <Touching Self>.

So clone 1 would be touching clone 5 and clone 5 would be touching clone 1, so you would likely be running the same detection script twice.
You just fried my brain… What?
scratchcode1_2_3
Scratcher
1000+ posts

How to detect touching a clone :/

I would recommend not coding it so that the sprite detects when it is touching the clone, rather when the clone is touching the sprite and broadcasting a signal that is has been touched.

The sprite making the clones:
when green flag clicked
set [id v] to [0] // make sure this is for this sprite only
repeat (number of clones)
change [id v] by [1]
add [] to [x v] // you don't need to put anything here
add [] to [y v] // you don't need to put anything here
add [] to [touching? v] // you don't need to put anything here
create clone of [myself v]

end
hide // the main sprite doesn't need to be shown unless you need, preferably I would hide it

when I start as a clone
forever
replace item (id) of [x v] with (x position)
replace item (id) of [y v] with (y position)
if <touching [sprite1 v] ?> then
replace item (id) of [touching? v] with [true]
end
end

Sprite1, or the one needing to detect the clones:
when green flag clicked
forever
set [i v] to [0]
repeat until <(item (id) of [touching? v] :: list) = [true]>
change [i v] by (1)
end
broadcast [i am touching clone v]
end

when I receive [i am touching clone v]
... // your code

Powered by DjangoBB