Discuss Scratch

TheOfficialDerpCo
Scratcher
14 posts

How can you make it so a sprite can't touch another sprite?

We're making a platformer, and we're trying to make it so the sprite can't go through other sprites. We've found a way, though sometimes it glitches.
It goes like this:
when I receive
foreverifkeyleft arrowpressed?andnottouchingthatpeskyground?thenchangexby-8nextcostumepointindirection-90

Halp!
lederniersamourai
Scratcher
500+ posts

How can you make it so a sprite can't touch another sprite?

Sometimes, when you step 8 units, sprites can touch each other.
So you have to test after the move and go back until not touching. When you go back, try to do it with smaller steps, but in any case try to be exactly at the initial place.

whenIreceiveStartforeverifkeyleft arrowpressed?andnottouchingthatpeskyground?thenchangexby-8repeatuntilnottouchingthatpeskyground?changexby-4nextcostumepointindirection-90
TheOfficialDerpCo
Scratcher
14 posts

How can you make it so a sprite can't touch another sprite?

Very interesting… Thanks for the thought.
gtoal
Scratcher
1000+ posts

How can you make it so a sprite can't touch another sprite?

There are two sprite-based ways to do this.

1) just move - if it touches, move back before the screen updates.

2) create an invisible sprite that is like the actual sprite but with an <n>-pixel wide boundary added to it. Then move until the boundary sprite touches the target. As long as your moves are not so large that the actual sprite can touch the target in a single move (ie < n), it should alert you before they actually collide.
TheOfficialDerpCo
Scratcher
14 posts

How can you make it so a sprite can't touch another sprite?

THANK YOU SO MUCH! THAT WORKS SO MUCH BETTER!
DamoDog
Scratcher
38 posts

How can you make it so a sprite can't touch another sprite?

gtoal wrote:

There are two sprite-based ways to do this.

1) just move - if it touches, move back before the screen updates.

2) create an invisible sprite that is like the actual sprite but with an <n>-pixel wide boundary added to it. Then move until the boundary sprite touches the target. As long as your moves are not so large that the actual sprite can touch the target in a single move (ie < n), it should alert you before they actually collide.
How would you move it back before a screen updates? i.e. a script example?
HOMELESSpotato08
Scratcher
22 posts

How can you make it so a sprite can't touch another sprite?

im stuck
lillywill
Scratcher
2 posts

How can you make it so a sprite can't touch another sprite?

how do you make a sprite that can touch another sprite but not go through it. im trying to make a game put when the person moves around it keeps going through walls and stuff.
Fischer57
Scratcher
100+ posts

How can you make it so a sprite can't touch another sprite?

lillywill wrote:

how do you make a sprite that can touch another sprite but not go through it. im trying to make a game put when the person moves around it keeps going through walls and stuff.

HOMELESSpotato08 wrote:

im stuck
Guys lease make another forum about this. This is Necroposting.
latin_gamerX
Scratcher
500+ posts

How can you make it so a sprite can't touch another sprite?

foreveriftouchingsprite?thenchangexby15changeyby15
Fischer57
Scratcher
100+ posts

How can you make it so a sprite can't touch another sprite?

latin_gamerX wrote:

foreveriftouchingsprite?thenchangexby15changeyby15
Please don't necropost
0nonimus_Goomber2
Scratcher
4 posts

How can you make it so a sprite can't touch another sprite?

Step 1: When Green Flag Clicked Block.
Step 2: Set Default position.
Step 3: Do A Forever Block.
Step 4: Do an If _____ Then Block.
Step 5: Change X and Y to 5 and 5 then -5 and -5
whenclickedswitchcostumetosetxtosetytoforeverifthenchangexbychangeybyendend
0nonimus_Goomber2
Scratcher
4 posts

How can you make it so a sprite can't touch another sprite?

Step 1: When Green Flag Clicked Block.
Step 2: Set Default position.
Step 3: Do A Forever Block.
Step 4: Do an If _____ Then Block.
Step 5: Change X and Y to 5 and 5 then -5 and -5
whenclickedswitchcostumeto 1setxtosetytoforeverifthentouching sprite ??changeyby5changexby5endend
theanonymousweirdo
Scratcher
500+ posts

How can you make it so a sprite can't touch another sprite?

0nonimus_Goomber2 wrote:

Step 1: When Green Flag Clicked Block.
Step 2: Set Default position.
Step 3: Do A Forever Block.
Step 4: Do an If _____ Then Block.
Step 5: Change X and Y to 5 and 5 then -5 and -5
whenclickedswitchcostumetosetxtosetytoforeverifthenchangexbychangeybyendend

Please check the date that the topic was originally posted before posting. This topic was made in 2016

Last edited by theanonymousweirdo (Oct. 22, 2020 00:36:08)

FLORAIDER
Scratcher
5 posts

How can you make it so a sprite can't touch another sprite?

whenclickedforeveriftouching Wall?thenchangexby15changeyby15move10stepsMe=Hope i helped :D

Last edited by FLORAIDER (Nov. 17, 2020 03:24:48)

mysterious-neutron
Scratcher
1000+ posts

How can you make it so a sprite can't touch another sprite?

FLORAIDER wrote:

whenclickedforeveriftouching Wall?thenchangexby15changeyby15move10stepsMe=Hope i helped :D
Please don't necropost
Bannervessel6
Scratcher
1 post

How can you make it so a sprite can't touch another sprite?

Hey! uh, I'm trying to make it so that one of my sprites and stand on another sprite the “ground” sprite, this is not the actual ground sprite that I have, just a different one, but how do I make it so that it can go on top of it?
goldenlion06
Scratcher
500+ posts

How can you make it so a sprite can't touch another sprite?

whenclickedforevermakesurethisdoeshaverunwithoutscreenrefreshgetouttaceiling



definemakesurethisdoeshaverunwithoutscreenrefreshgetouttafloor/ceilingiftouchingfloor/ceiling?thenrepeatuntilnottouchingfloor/ceiling ?changeyby1or-1
end

Last edited by goldenlion06 (Feb. 6, 2021 17:19:18)

goldenlion06
Scratcher
500+ posts

How can you make it so a sprite can't touch another sprite?

change the “if touching floor to wall and set the change y by to change x by” to make it for walls
goldenlion06
Scratcher
500+ posts

How can you make it so a sprite can't touch another sprite?

FLORAIDER wrote:

whenclickedforeveriftouching Wall?thenchangexby15changeyby15move10stepsMe=Hope i helped :D

bro what if the wall isnt 15 pixels long? thas why you look at my comment and see that it changes x/y by 1 or -1 repeatedly without the any changes on screen so it stops exactly at the wall and doesnt even seem like you went through wall

Powered by DjangoBB