Discuss Scratch

cgkas
New Scratcher
1 post

How to disappear sprite when touches other sprite?

Hi all, I hope you´re fine.

I have one sprite1 on the left and sprite2 that moves from right edge to left edge. I´d like to disappear both when they touch each other or disappear sprite2 if touch sprite1 or reaches any edge.

In sprite2 I have this code but doesn´t disappear(hide) when touches sprite1. What I'm doing wrong?

Thanks in advance for any help.


when green flag clicked 
forever
show
go to x: (230) y: (0)
glide (2) secs to x: (-245) y: (0)
if <<touching [edge] ?> or <touching [sprite1] ?>> then
hide
end
end
deck26
Scratcher
1000+ posts

How to disappear sprite when touches other sprite?

Are you hiding sprite1 in the same way? If so whichever of sprite1 and sprite2 runs their script first will hide but then not be there for the other sprite to detect the touch. Add a wait 0 secs before the hide. That allows the other script time to run.
BladiPetrov
Scratcher
100+ posts

How to disappear sprite when touches other sprite?

Note that the “glide” block runs separately from all, so if the sprite is touching it while it is gliding, it won't detect it. If this is what is happening, try putting the detection script in a separate script
Ghxstifyy
Scratcher
100+ posts

How to disappear sprite when touches other sprite?

I think it may be because of the ‘forever’ block.. it is basically telling the project to forever show
deck26
Scratcher
1000+ posts

How to disappear sprite when touches other sprite?

Ghxstifyy wrote:

I think it may be because of the ‘forever’ block.. it is basically telling the project to forever show
But by the end of the loop it will hide the sprite again if the conditions dictate that and the frame is only redrawn then.

Last edited by deck26 (March 1, 2024 15:17:56)

cgkas
New Scratcher
1 post

How to disappear sprite when touches other sprite?

Thank you all, I've tried as suggested by BladiPetrov, putting the detection block in a different script and now works better but still is not working as I would like.

Below I share a simple version where the bear wants to eat the jar. So when the bear touches the jar, I want to hide the jar and a new jar appears at right edge to repeat the process.

Maybe someone can take a look. Thanks

https://scratch.mit.edu/projects/975064707/
bsbdxgesbhjdb
Scratcher
3 posts

How to disappear sprite when touches other sprite?

BladiPetrov wrote:

Note that the “glide” block runs separately from all, so if the sprite is touching it while it is gliding, it won't detect it. If this is what is happening, try putting the detection script in a separate script
thankyou!!! this helps alot!!

Powered by DjangoBB