Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » Clone collisions (Detecting which clones collide)
- ABC124816
- Scratcher
100+ posts
Clone collisions (Detecting which clones collide)
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.
Last edited by ABC124816 (March 30, 2023 16:58:17)
ABC124816 NEWS: We've crossed the 100 posts mark!
Developer of the lagless theory!
Love these blocks!
(timer)Block of the time (I might suggest adding it if it is sensible):
(days since 2000)
pause all scripts in project for (3) seconds::control
- legendary34678
- Scratcher
1000+ posts
Clone collisions (Detecting which clones collide)
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.
Can you beat my latest game?
Have you heard of the X Y Problem?
Please check out me projects please I'm desperate –> Idle Balls, Candy Grab!, Don't Move Your Mouse!, Rude Robot, Tic Tac Toe, Memory Game, Corn Maze, and Idle Balls PEN EDITION!
Oh, hey! I have 100+ posts now!
Oh, hey! I have 500+ posts now! (8/26/22)
Oh, hey! I have 1000+ posts now! (9/23/22)
(Thanks to @AntonL1kesPotato for helping me figure out how to add a signature!)
- ABC124816
- Scratcher
100+ posts
Clone collisions (Detecting which clones collide)
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.
ABC124816 NEWS: We've crossed the 100 posts mark!
Developer of the lagless theory!
Love these blocks!
(timer)Block of the time (I might suggest adding it if it is sensible):
(days since 2000)
pause all scripts in project for (3) seconds::control
- B1j2754
- Scratcher
36 posts
Clone collisions (Detecting which clones collide)
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.
https://scratch.mit.edu/projects/805860143/
I have been scratching for about 3 years now, and most of my projects are all starts, rarely finished, due to the many issues that I run into when making my projects too in-depth.
when green flag clicked
set [Will this project be finished ever?] to (pick random (1) to (100))
if <(Will this project be finished ever?) = [13]> then
say [no way!]
finish project
else
start a new project
end
- legendary34678
- Scratcher
1000+ posts
Clone collisions (Detecting which clones collide)
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.
Can you beat my latest game?
Have you heard of the X Y Problem?
Please check out me projects please I'm desperate –> Idle Balls, Candy Grab!, Don't Move Your Mouse!, Rude Robot, Tic Tac Toe, Memory Game, Corn Maze, and Idle Balls PEN EDITION!
Oh, hey! I have 100+ posts now!
Oh, hey! I have 500+ posts now! (8/26/22)
Oh, hey! I have 1000+ posts now! (9/23/22)
(Thanks to @AntonL1kesPotato for helping me figure out how to add a signature!)
- vladfein
- Scratcher
100+ posts
Clone collisions (Detecting which clones collide)
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/
- ABC124816
- Scratcher
100+ posts
Clone collisions (Detecting which clones collide)
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/
ABC124816 NEWS: We've crossed the 100 posts mark!
Developer of the lagless theory!
Love these blocks!
(timer)Block of the time (I might suggest adding it if it is sensible):
(days since 2000)
pause all scripts in project for (3) seconds::control
- deck26
- Scratcher
1000+ posts
Clone collisions (Detecting which clones collide)
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.
- grandpasp
- Scratcher
36 posts
Clone collisions (Detecting which clones collide)
I don't know if you are still looking, but I just shared a project that does clone-to-clone collision identification
- grandpasp
- Scratcher
36 posts
Clone collisions (Detecting which clones collide)
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
- BigNate469
- Scratcher
500+ posts
Clone collisions (Detecting which clones collide)
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
Highlight any part of this signature and press ctrl+shift+down arrow to see the rest of it
foreverPlease read the list of Officially Rejected Suggestions before posting a suggestion for Scratch! 100th post
if <person asks [what's a signature] :: sensing> then
Redirect to [https://en.scratch-wiki.info/wiki/Signature] :: motion
end
end
This signature is designed to be as helpful as possible.
View all of the topics you've posted in:
https://scratch.mit.edu/discuss/search/?action=show_user&show_as=topics
View all of your posts:
https://scratch.mit.edu/discuss/search/?action=show_user&show_as=posts
Forum tips:
Don't title topics something like “HELP ME!!!”. It's not helpful, and won't get you as many responses.
Don't post in topics where the latest post is over ~2 months old, unless you have something critical to add. Especially in topics that are several years old- it isn't helpful, and is known as necroposting.
Don't post unrelated things in topics, including questions of your own. Make a new topic for your questions.
You can use the
[code] and [/code]
You can use the
[color=color name or hexadecimal value here] and [/color]
Little-known Scratch URLs:
scratch.pizza (redirects to main page)
https://scratch.mit.edu/projects/PROJECT ID HERE/remixtree (replace “PROJECT ID HERE” with project id number. Shows all the remixes of the project, and the remixes of those projects, and the remixes of those projects, and so on, as a chart. Link currently redirects to one of my projects)
- grandpasp
- Scratcher
36 posts
Clone collisions (Detecting which clones collide)
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
- Discussion Forums
- » Help with Scripts
- » Clone collisions (Detecting which clones collide)