Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » How to make a boundary in scratch?
- TheOverlordBunny
-
Scratcher
13 posts
How to make a boundary in scratch?
I am planning on making a small little shooter game and I want to make it so the player can't go past a certain wall.
I think this would work but I'm not sure
I think this would work but I'm not sure
when green flag clicked
forever
if <touching [boundary] ?> then
move (-10) steps
end
end
Last edited by TheOverlordBunny (Jan. 23, 2021 00:52:47)
- pkhead
-
Scratcher
1000+ posts
How to make a boundary in scratch?
here is a simple solution:
lol haha there was a typo in the scratchblocks code HAHAHAHAHA
this makes it so when a player moves a certain direction, it moves it and then checks if the player is in a wall. if it is, it moves the player backwards to where hopefully there was no wall
(i haven't actually tested yet but in theory it would work)
foreverlol forgot the closing tag
if <key [right arrow v] pressed?> then
change x by (speed)
if <touching [boundary v]> then
change x by (() - (speed))
end
end
if <key [left arrow v] pressed?> then
change x by (() - (speed))
if <touching [boundary v]> then
change x by (() - (speed))
end
end
if <key [up arrow v] pressed?> then
change y by (speed)
if <touching [boundary v]> then
change y by (() - (speed))
end
end
if <key [down arrow v] pressed?> then
change y by (() - (speed))
if <touching [boundary v]> then
change y by (() - (speed))
end
end
lol haha there was a typo in the scratchblocks code HAHAHAHAHA
this makes it so when a player moves a certain direction, it moves it and then checks if the player is in a wall. if it is, it moves the player backwards to where hopefully there was no wall
(i haven't actually tested yet but in theory it would work)
Last edited by pkhead (Jan. 23, 2021 01:49:44)
- pkhead
-
Scratcher
1000+ posts
How to make a boundary in scratch?
what is there some sort of edit limit because i'm a new scratcher or something ugh… well by “typo” i mean there was a missing “end”
- TheOverlordBunny
-
Scratcher
13 posts
How to make a boundary in scratch?
or I could've just done this
when green flag clickedand that would do it just fine but thanks for your suggestion
forever
if <touching [boundary] ?> then
change y by (-5)
end
end
- pkhead
-
Scratcher
1000+ posts
How to make a boundary in scratch?
or I could've just done thiswell you never told me which sides the player would be able to hit the boundary, so i had nought but to assume that the player could hit it on all sideswhen green flag clickedand that would do it just fine but thanks for your suggestion
forever
if <touching [boundary] ?> then
change y by (-5)
end
end
- TheOverlordBunny
-
Scratcher
13 posts
How to make a boundary in scratch?
wow, that was a fast reply and the cat is going up/down. But I guess I'll try your method since mine is letting the cat go through the boundaries and then he's just gliding out of them.
say [thanks for the help!]
think [well now it's time to code (or maybe go to sleep?)]
- TheOverlordBunny
-
Scratcher
13 posts
How to make a boundary in scratch?
here is the moving script i'm using
when green flag clicked
forever
if <key [a] pressed?> then
change x by (left)
end
if <key [d] pressed?> then
change x by (right)
end
if <key [w] pressed?> then
change y by (up)
end
if <key [s] pressed?> then
change y by (down)
end
- gremlinsure
-
New Scratcher
1 post
How to make a boundary in scratch?
im new to scratch do I put all this into the sprite or background?
I figured it out
I figured it out
Last edited by gremlinsure (Oct. 15, 2025 16:41:17)
- abhaithebest
-
Scratcher
27 posts
How to make a boundary in scratch?
I am planning on making a small little shooter game and I want to make it so the player can't go past a certain wall.Here is one way to do this:
I think this would work but I'm not surewhen green flag clicked
forever
if <touching [boundary] ?> then
move (-10) steps
end
end
when @greenFlag clicked
go to x: [...] y: [...]
forever
set rotation style [ don't rotate v]
... // movement script goes here
if <touching (boundary v)?>then
point towards (boundary v)
move [the amount away you want your sprite to move] steps
end
end
Last edited by abhaithebest (Oct. 16, 2025 00:08:31)
- Lpea42
-
Scratcher
100+ posts
How to make a boundary in scratch?
Super efficient script made by griffpatch, better than anything anyone else came up with here:
define Collision
repeat until <not <touching [wall v] ?>>
move (-1) steps
end
when flag clicked
forever
movement
Collision
end
- ilikerats4
-
Scratcher
78 posts
How to make a boundary in scratch?
or I could've just done thisi havent read this full yet, but heres a promblam, go to the wall facing towards it. and then face away. it will shove you trough itwhen green flag clickedand that would do it just fine but thanks for your suggestion
forever
if <touching [boundary] ?> then
change y by (-5)
end
end

- ilikerats4
-
Scratcher
78 posts
How to make a boundary in scratch?
Super efficient script made by griffpatch, better than anything anyone else came up with here:someone can walk to the wall. press aginst it and then look away and theyd pass it trough itdefine Collision
repeat until <not <touching [wall v] ?>>
move (-1) steps
end
when flag clicked
forever
movement
Collision
end
- Discussion Forums
- » Help with Scripts
-
» How to make a boundary in scratch?





