Clone collisions (Detecting which clones collide)
id: 673377
category: Help with Scripts
posts: 13
Mar 30, 2023 16:56:57
Clone collisions (Detecting which clones collide)
view on scratch
view on legacy ocular
ABC124816
loading
So, recently I had this problem of detecting clone collisions. In the past, it was a piece of cake for detecting clone collisions.
For clones of a sprite named ‘Sprite1’ this predicate does the trick:
Identifying clones is easy enough, just use a sprite-local variable:
I thought of storing the clone ids one after the other in a single variable called:
Now to tackle the problem of storing the id's. The clones which collided at some instant will both report:
For clones of a sprite named ‘Sprite1’ this predicate does the trick:
<touching (join[Sprite1]()) ?>However, now I am faced with detecting which clones collide.
Identifying clones is easy enough, just use a sprite-local variable:
(id)And do this:
when green flag clickedBut detecting which clones collide is a serious problem.
set [id v] to (0)
repeat [how many clones you want]
change [id v] by (1)
create clone of [myself v]
end
I thought of storing the clone ids one after the other in a single variable called:
(clones collided)For the sake of simplicity, I will assume at most 9 clones are created (which is enough for my purposes as of now and can be generalized later if needed), so that:
(letter (1) of (clones collided))and
(letter (2) of (clones collided))will give the id's of the clones collided.
Now to tackle the problem of storing the id's. The clones which collided at some instant will both report:
<touching (join[Sprite1]()) ?>as true at that instant, as saying clone 1 is touching clone 2 is the same as saying clone 2 is touching clone 1, so in order one after the other is simply breaking this symmetry. We could do this:
when green flag clickedSuppose we test this script with clone 1 and clone 2. Since both will report:
forever
if <touching (join[Sprite1]()) ?> then
set [clones collided v] to (join(clones collided)(id))
end
end
<touching (join[Sprite1]()) ?>as true at the same instant, we run at the problem where both clones try to add their id's at the same time, so what does:
(clones collided)even report? Because both of them do this at the same time, something must go wrong, I don't know what. So how do we detect which clones collide with each other if this solution doesn't work? This almost feels like a paradox.
Mar 30, 2023 18:21:11
Clone collisions (Detecting which clones collide)
view on scratch
view on legacy ocular
legendary34678
loading
The only thing you will be able to tell is if a clone is touching another clone and not which clone is touching which. The reason for this is because the only block you can use to detect clone collisions is the touching sprite boolean block which cannot tell clones apart from each other. You could try to track all of the collisions in a list and then detect which clones are close to each other, but it will not be foolproof.
Mar 30, 2023 18:44:57
Clone collisions (Detecting which clones collide)
view on scratch
view on legacy ocular
ABC124816
loading
I have seen quite a few quite a few projects which CAN detect which clones collide, so it is definitely possible. But it is only a small part of massive projects, so looking at the code just wouldn't do any good. The only thing you will be able to tell is if a clone is touching another clone and not which clone is touching which. The reason for this is because the only block you can use to detect clone collisions is the touching sprite boolean block which cannot tell clones apart from each other. You could try to track all of the collisions in a list and then detect which clones are close to each other, but it will not be foolproof.
Mar 30, 2023 20:22:23
Clone collisions (Detecting which clones collide)
view on scratch
view on legacy ocular
B1j2754
loading
I am not sure how the bigger projects do it, but one method you can apply is adding the coordinates (x and y) and the clone's name/use into a list. Each one will be given its own item. Then you have two options. You can have more clones that act as hitboxes, and detect collision that way, or have a sprite constantly looking at the list, looking for a collision based on how close the x and y coordinates of differents sprites are to each other. It would take a lot, but doable. I will look into how people like GRiffpatch and other big names do it for you.
Mar 30, 2023 22:50:17
Clone collisions (Detecting which clones collide)
view on scratch
view on legacy ocular
legendary34678
loading
Yep, that's the method I suggested: comparing coordinates to see how close clones are to each other. The only issue with this is what happens if there's a huge crowd of clones? Sure, comparing coordinates works for two clones, but probably not for twenty.
Mar 30, 2023 23:50:55
Clone collisions (Detecting which clones collide)
view on scratch
view on legacy ocular
vladfein
loading
So how do we detect which clones collide with each other if this solution doesn't work? This almost feels like a paradox.
I think I've solved this problem by inserting “wait 0 seconds” (basically, “yield”) in the procedure, to get another colliding clone a chance to also detect that collision.
Please see: https://scratch.mit.edu/projects/828819164/
Mar 31, 2023 11:01:22
Clone collisions (Detecting which clones collide)
view on scratch
view on legacy ocular
ABC124816
loading
Nice: Thanks for the tip! (I actually tried the ‘wait 0 seconds’ method, but turns out that I made the wait before adding the id's)So how do we detect which clones collide with each other if this solution doesn't work? This almost feels like a paradox.
I think I've solved this problem by inserting “wait 0 seconds” (basically, “yield”) in the procedure, to get another colliding clone a chance to also detect that collision.
Please see: https://scratch.mit.edu/projects/828819164/
Mar 31, 2023 11:06:56
Clone collisions (Detecting which clones collide)
view on scratch
view on legacy ocular
deck26
loading
You also don't need the join trick for sprite1 clones to detect touching sprite1 clones, just copy the touching block from another sprite after changing it so sprite1 is selected in the drop-down.
Mar 27, 2024 17:11:51
Clone collisions (Detecting which clones collide)
view on scratch
view on legacy ocular
grandpasp
loading
I don't know if you are still looking, but I just shared a project that does clone-to-clone collision identification
Mar 27, 2024 17:23:33
Clone collisions (Detecting which clones collide)
view on scratch
view on legacy ocular
kingKASEtheGREATalt
loading
dont necropost I don't know if you are still looking, but I just shared a project that does clone-to-clone collision identification
Mar 27, 2024 17:32:21
Clone collisions (Detecting which clones collide)
view on scratch
view on legacy ocular
grandpasp
loading
What's that mean?dont necropost I don't know if you are still looking, but I just shared a project that does clone-to-clone collision identification
Mar 27, 2024 19:33:32
Clone collisions (Detecting which clones collide)
view on scratch
view on legacy ocular
BigNate469
loading
It's posting in an old topic that hasn't received activity in a while and can be considered spam.What's that mean?dont necropost I don't know if you are still looking, but I just shared a project that does clone-to-clone collision identification
Mar 27, 2024 19:36:46
Clone collisions (Detecting which clones collide)
view on scratch
view on legacy ocular
grandpasp
loading
Thanks! I did not know that.It's posting in an old topic that hasn't received activity in a while and can be considered spam.What's that mean?dont necropost I don't know if you are still looking, but I just shared a project that does clone-to-clone collision identification