Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » HOW TO DO COLLISIONS ON MY GAME???
- Megalonaut
-
Scratcher
10 posts
HOW TO DO COLLISIONS ON MY GAME???
Ok, so, basically, I'm working on a top-down game, and right now, I don't really know what it is about, I'm just testing until I do the movement just right then focus on the other parts of the game. My whole movement system is kinda complicated, since it's a scrolling top-down, the fact that the strafing was replaced by a rotation of the character's head, which is really cool, but also complicates it even more. The only problem I have though, is not a tiny one, as I have 0 idea on how to make the wall collisions and stop the player or an object like the box from just ignoring the wall. PLEASE HELP!
https://scratch.mit.edu/projects/889673361/
this is the game btw, only shared it to get help
https://scratch.mit.edu/projects/889673361/
this is the game btw, only shared it to get help
- Megalonaut
-
Scratcher
10 posts
HOW TO DO COLLISIONS ON MY GAME???
btw if u guys cant tell the grey thing is supposed to be walls
- qwertycodechamp90411
-
Scratcher
100+ posts
HOW TO DO COLLISIONS ON MY GAME???
Easy method:
Hard Method:
move (5) steps
if <touching [wall v] ?> then
move (-5) steps
end
Hard Method:
define move (x) steps with wall collision
change x by ((x) * ([cos v] of ((90) - (direction))))
if <touching [wall v] ?> then
change x by (((0) - (x)) * ([cos v] of ((90) - (direction)))) // negative
end
change y by ((x) * ([sin v] of ((90) - (direction))))
if <touching [wall v] ?> then
change y by (((0) - (x)) * ([sin v] of ((90) - (direction)))) // negative
end
- Megalonaut
-
Scratcher
10 posts
HOW TO DO COLLISIONS ON MY GAME???
alright, thanks for answering! ill test that out right now!
- Megalonaut
-
Scratcher
10 posts
HOW TO DO COLLISIONS ON MY GAME???
it kinda works, but if i just spin a little it breaks and i just phase thru the wall, I think you didn't check out the project, the wall collision needs to be compatible with the movement system, and this one is good but its for more straight-forward simple top-down games
- Megalonaut
-
Scratcher
10 posts
HOW TO DO COLLISIONS ON MY GAME???
ok, i did the smart thing and made a hitbox, but now the problem is that whenever i touch the wall i cant escape and just get stuck there
- Megalonaut
-
Scratcher
10 posts
HOW TO DO COLLISIONS ON MY GAME???
im thinking that if nobody finds a solution i might have to just not put in any walls in the game, maybe I can just use kill blocks that send the player to the start
- Megalonaut
-
Scratcher
10 posts
HOW TO DO COLLISIONS ON MY GAME???
Thanks for the help! Even though it doesn't work in my current situation, I still appreciate it!
Easy method:move (5) steps
if <touching [wall v] ?> then
move (-5) steps
end
Hard Method:define move (x) steps with wall collision
change x by ((x) * ([cos v] of ((90) - (direction))))
if <touching [wall v] ?> then
change x by (((0) - (x)) * ([cos v] of ((90) - (direction)))) // negative
end
change y by ((x) * ([sin v] of ((90) - (direction))))
if <touching [wall v] ?> then
change y by (((0) - (x)) * ([sin v] of ((90) - (direction)))) // negative
end[/quote]
Last edited by Megalonaut (Sept. 6, 2023 15:09:52)
- sashimiricedev
-
Scratcher
100+ posts
HOW TO DO COLLISIONS ON MY GAME???
I may have the solution to your problem. I have a studio dedicated to helping Scratchers with common problems. It's small for now, but I plan on adding more projects and demos to it.
Link to project: https://scratch.mit.edu/projects/891352927/
Link to studio: https://scratch.mit.edu/studios/33415081/
Hope this helps. Comment on the project or my profile if it doesnt.
Link to project: https://scratch.mit.edu/projects/891352927/
Link to studio: https://scratch.mit.edu/studios/33415081/
Hope this helps. Comment on the project or my profile if it doesnt.
Last edited by sashimiricedev (Sept. 11, 2023 21:17:00)
- Cobman57
-
Scratcher
1 post
HOW TO DO COLLISIONS ON MY GAME???
thanks, the collisions work really well
say [Thank you!]
- samitha_4_A
-
Scratcher
3 posts
HOW TO DO COLLISIONS ON MY GAME???
Im making a Golf game end everytime I try to make collisions the ball ends up going inside the level can anyone write a piece of code for that?
- thesammycultist
-
Scratcher
1 post
HOW TO DO COLLISIONS ON MY GAME???

Last edited by thesammycultist (May 29, 2025 15:07:55)
- NMario84
-
Scratcher
1000+ posts
HOW TO DO COLLISIONS ON MY GAME???
Ya'll REALLY need to stop necroposting all these topics.
- Effortless-Coding
-
Scratcher
35 posts
HOW TO DO COLLISIONS ON MY GAME???
You could make a hitbox for the player. Create four walls that are kinda surrounding the player. One wall on the top, bottom, left, and right. If the right wall touches a collision, then move the player to the left, and etcetera.
If you need help creating the engine, send me a message and I’ll give you code!
Btw I’m not trying to advertise but I have the sprite used in my Effortless’ World game, so maybe you could look into that and figure it out!
This fixes the issue where the player could phase through the walls ocasionally.
If you need help creating the engine, send me a message and I’ll give you code!
Btw I’m not trying to advertise but I have the sprite used in my Effortless’ World game, so maybe you could look into that and figure it out!
This fixes the issue where the player could phase through the walls ocasionally.
- N8_D_GR8_1
-
Scratcher
1000+ posts
HOW TO DO COLLISIONS ON MY GAME???
You could make a hitbox for the player. Create four walls that are kinda surrounding the player. One wall on the top, bottom, left, and right. If the right wall touches a collision, then move the player to the left, and etcetera.Just so that you know, necroposting (posting on old topics) is not generally something you are supposed to do. When you see someone necroposting, advise them to stop and to create a new topic.
If you need help creating the engine, send me a message and I’ll give you code!
Btw I’m not trying to advertise but I have the sprite used in my Effortless’ World game, so maybe you could look into that and figure it out!
This fixes the issue where the player could phase through the walls ocasionally.
- Discussion Forums
- » Help with Scripts
-
» HOW TO DO COLLISIONS ON MY GAME???









