Discuss Scratch

Ask_Pinkamena
Scratcher
51 posts

Sprite touching anything

I have searched for a solution on the forums, and correct me if I am wrong, there is no topic on a touching anything script. What I want to do is have one sprite perform a certain action upon contacting any sprite. I know I could use a broadcast on every sprite, but I am hoping there is a faster alternative as a single script. Any help is appreciated.

Edit: By anything, I mean anything (other sprites, the edges, anything BUT the background).

Last edited by Ask_Pinkamena (July 19, 2015 01:49:22)



Since clans are apparently a thing, I propose the Gemini Faction. Just to be special.
gor-dee
Scratcher
1000+ posts

Sprite touching anything

you could use
<<<touching [sprite1] ?> or < <touching [sprite2] ?>>> or <<touching [edge] ?> >>
but this might cause lag if there are a lot of sprites. An improvement on this would be
if <(distance to [sprite1]) < [50 ]> then
if <touching [sprite1] ?> then
broadcast [do something]

end
else
if <(distance to [sprite2]) < [50 ]> then
if <touching [sprite2] ?> then
broadcast [do something]

end
else
if <touching [edge] ?> then
broadcast [do something]

end


end


end

this works faster because the distance to block works faster than the touching block. You need to put a value where I've put 50 that is approximately the smallest distance between the centres of the two sprites when they are nearly touching. This way your script will only use the laggy touching block if the two sprites are near enough to touch. Hope this makes sense!
Ask_Pinkamena
Scratcher
51 posts

Sprite touching anything

gor-dee wrote:

you could use
<<<touching [sprite1] ?> or < <touching [sprite2] ?>>> or <<touching [edge] ?> >>
but this might cause lag if there are a lot of sprites. An improvement on this would be
if <(distance to [sprite1]) < [50 ]> then
if <touching [sprite1] ?> then
broadcast [do something]

end
else
if <(distance to [sprite2]) < [50 ]> then
if <touching [sprite2] ?> then
broadcast [do something]

end
else
if <touching [edge] ?> then
broadcast [do something]

end


end


end

this works faster because the distance to block works faster than the touching block. You need to put a value where I've put 50 that is approximately the smallest distance between the centres of the two sprites when they are nearly touching. This way your script will only use the laggy touching block if the two sprites are near enough to touch. Hope this makes sense!
This could work. Thanks!


Since clans are apparently a thing, I propose the Gemini Faction. Just to be special.
NeoProHex
Scratcher
12 posts

Sprite touching anything

I guess you could just have multiple scripts for each of the sprites. Or maybe a creative use of the More Blocks tab.

You probably haven't heard of me, but I have a few projects in the works you may be interested in!

If your a Five Nights at Freddy's fan that wants to play the game but doesn't have the money and all the scratch ones are too laggy and incomplete on your computer? Well, then I have the project for you. I have began to remake the first game and make it so it doesn't have all of the effects and unnecessary graphics that made the game laggy. It will eventually become a full project will all the gameplay of the original game, but I need your help! Check out the project here, it is in early stages of development. To be an alpha/beta tester, check it out here

Stay tuned for more projects by following me at NeoProHex
Ask_Pinkamena
Scratcher
51 posts

Sprite touching anything

NeoProHex wrote:

I guess you could just have multiple scripts for each of the sprites. Or maybe a creative use of the More Blocks tab.
While I appreciate the response, I am looking for a single script answer. Your second answer could work for what I need.


Since clans are apparently a thing, I propose the Gemini Faction. Just to be special.
DrEthan
Scratcher
6 posts

Sprite touching anything

i would love an answer to this because i am creating a dynamic inventory (which means that when you pick up an item it can go to any slot not just a set one). But my problem is that there is a chance that you might pick up two items at the same time and if you do that the dynamic inventory gets messed up with the items being on top of each other. The only way i could fix this is by having scripts that say if touching this or this or this which if i am trying to make a lot of items wouldn't be efficient so what i want is a script that can sense if i am touching anything else except this. (this is my game btw https://scratch.mit.edu/projects/95030060/#player)
DrEthan
Scratcher
6 posts

Sprite touching anything

Ok i found a way to do this, I found out that if you type the exact name of all your sprites into a list and then tell the sprite to sense if it is touching anything in that list it will do something. An example i made would be this project https://scratch.mit.edu/projects/101852148/#editor
DrEthan
Scratcher
6 posts

Sprite touching anything

i actually dont think anyone will view this forum because the user who started this is now gone ._. welp.
LilPikachu08
Scratcher
69 posts

Sprite touching anything

when green flag clicked
forever

move (10) steps
if on edge, bounce
if <touching color [#ff0209] ?> then
stop [all v]

end
if <touching [Paddle v] ?> then
turn ccw (100) degrees

end

end
this is when the ball touches red line fail hard
LilPikachu08
Scratcher
69 posts

Sprite touching anything

DrEthan wrote:

i actually dont think anyone will view this forum because the user who started this is now gone ._. welp.
you mean this
DrEthan
Scratcher
6 posts

Sprite touching anything

LilPikachu08 wrote:

DrEthan wrote:

i actually dont think anyone will view this forum because the user who started this is now gone ._. welp.
you mean this
what?
Jemmerl
Scratcher
100+ posts

Sprite touching anything

Sorry if this is necroposting, but DrEthan- thank you. I was looking for something like that!

Always use message1. The gods of Scratch gave it to you for a reason.
DrEthan
Scratcher
6 posts

Sprite touching anything

Jemmerl wrote:

Sorry if this is necroposting, but DrEthan- thank you. I was looking for something like that!
your welcome

Powered by DjangoBB

Standard | Mobile