Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » How can you make it so a sprite can't touch another sprite?
- 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
Halp!
It goes like this:when I receive
forever
if <<key [left arrow] pressed?> and <not <touching [thatpeskyground] ?>>> then
change x by (-8)
next costume
point in direction (-90)
end
end
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.
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.
when I receive [Start]
forever
if <<key [left arrow] pressed?> and <not <touching [thatpeskyground] ?>>> then
change x by (-8)
repeat until <not <touching [thatpeskyground] ?>>
change x by (-4)
end
next costume
point in direction (-90)
end
end
- 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.
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?
There are two sprite-based ways to do this.How would you move it back before a screen updates? i.e. a script example?
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.
- 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?
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.
im stuckGuys 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?
forever
if <touching [sprite v] ?> then
change x by (15)
change y by (15)
end
end
- Fischer57
-
Scratcher
100+ posts
How can you make it so a sprite can't touch another sprite?
Please don't necropostforever
if <touching [sprite v] ?> then
change x by (15)
change y by (15)
end
end
- 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
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
when green flag clicked
switch costume to [ v]
set x to ()
set y to ()
forever
if <> then
change x by ()
change y by ()
endend
- 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
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
when green flag clicked
switch costume to [ 1]
set x to ()
set y to ()
forever
if <> then
<touching [ sprite ?] ?>
change y by (5)
change x by (5)
endend
- theanonymousweirdo
-
Scratcher
500+ 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 -5when green flag clicked
switch costume to [ v]
set x to ()
set y to ()
forever
if <> then
change x by ()
change y by ()
endend
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?
when green flag clicked
forever
if <touching [ Wall] ?> then
change x by (15)
change y by (15)
move (10) steps
end
end
<[Me] = [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?
Please don't necropostwhen green flag clicked
forever
if <touching [ Wall] ?> then
change x by (15)
change y by (15)
move (10) steps
end
end
<[Me] = [Hope i helped :D]>
- 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?
when green flag clicked
forever
(make sure this does have run without screen refresh) get outta ceiling
end
define (make sure this does have run without screen refresh) get outta floor/ceilingend
if <touching [floor/ceiling] ?> then
repeat until <<not <<touching [floor/ceiling ] ?>
change y by (1 or -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?
when green flag clicked
forever
if <touching [ Wall] ?> then
change x by (15)
change y by (15)
move (10) steps
end
end
<[Me] = [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
- Discussion Forums
- » Help with Scripts
-
» How can you make it so a sprite can't touch another sprite?