Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » collision works, unless you both keep sliding into the wall while walk towards the wall, please help.
- DNQ_brwn
-
Scratcher
30 posts
collision works, unless you both keep sliding into the wall while walk towards the wall, please help.
Hello, I need help with collision detection in my game,
I tried to do collision detection on based on some scrolling platformer detection method but I coded it over and over again because something was still wrong, collision does work but it's still jittery and buggy,
1. It could only fix collisions when you walk into a wall until you slide into the wall multiple times!
keep sliding and holding arrow keys at the same time towards the wall until the player glitches through the wall or dies and you'll see what I mean.
2. the green vertical hitbox thinks the player is deep in the ground and tries to move vertically of the floor, then it thinks that the player was crushed by something then the collision detection fails,
I still don't believe it's working 100% for that reason
Any ideas on how to fix this?
find this script,
It's responsible for scrolling colliding
the project is the link: https://scratch.mit.edu/projects/1137901998/.
Help would be appreciated, thanks!
I tried to do collision detection on based on some scrolling platformer detection method but I coded it over and over again because something was still wrong, collision does work but it's still jittery and buggy,
1. It could only fix collisions when you walk into a wall until you slide into the wall multiple times!
keep sliding and holding arrow keys at the same time towards the wall until the player glitches through the wall or dies and you'll see what I mean.
2. the green vertical hitbox thinks the player is deep in the ground and tries to move vertically of the floor, then it thinks that the player was crushed by something then the collision detection fails,
I still don't believe it's working 100% for that reason
Any ideas on how to fix this?
find this script,
define Move speed: (Speed) Input (Input)the script is in the Megaman//MegamanHitbox sprite.
go to x: ((Input) * (Speed)) y: (y position)
switch costume to (X-hitbox v)
WALL check ::custom block
set [current input v] to (Input)
change [P1 scroll x v] by ((Speed) * (Input)
if <<touching [ Level v] ?> or <(Touching?) > [0]>> then
set [last value v] to (direction)
set [moving? v] to [Scene-moving]
change [P1 scroll x v] by ((([floor v] of (() - (Speed))::operators)) * ((last input) * (1)))
point in direction (last value)
set [moving? v] to [true]
end
set [last input v] to (current input)
It's responsible for scrolling colliding
the project is the link: https://scratch.mit.edu/projects/1137901998/.
Help would be appreciated, thanks!
Last edited by DNQ_brwn (Feb. 27, 2025 14:04:40)
- Koamodo975
-
Scratcher
1000+ posts
collision works, unless you both keep sliding into the wall while walk towards the wall, please help.
I was gonna try and fix it but your code is hurting my brain abit, might try later when the sun's actually up
- DNQ_brwn
-
Scratcher
30 posts
collision works, unless you both keep sliding into the wall while walk towards the wall, please help.
I was gonna try and fix it but your code is hurting my brain abit, might try later when the sun's actually up
Ok, what part of the code were you struggling with?
- OrangeFlyingCat
-
Scratcher
100+ posts
collision works, unless you both keep sliding into the wall while walk towards the wall, please help.
You've made some mistakes that make it really hard for others to understand your code:
1. You have left a lot of hatless scripts.
2. Scripts overlap a lot.
3. You've made the engine while not testing it during the process.
All this makes the code barely readable and hard to remake from scratch.
And a cool fact: use ::type to change the type of a block in Scratchblocks:
1. You have left a lot of hatless scripts.
2. Scripts overlap a lot.
3. You've made the engine while not testing it during the process.
All this makes the code barely readable and hard to remake from scratch.
And a cool fact: use ::type to change the type of a block in Scratchblocks:
move (2) steps ::events
snip block lol ::grey
custom block ::custom
- DNQ_brwn
-
Scratcher
30 posts
collision works, unless you both keep sliding into the wall while walk towards the wall, please help.
You've made some mistakes that make it really hard for others to understand your code:I can understand the overlapping scripts and hatless script it's because I might put the code to the side because it might be useful and then I forget it and forgot to clean it up before sharing it., I've also spent too much time testing each part of the engine most important before I got stuck on scrolling collision detection. thanks for clarifying, I'll clean it up now.
1. You have left a lot of hatless scripts.
2. Scripts overlap a lot.
3. You've made the engine while not testing it during the process.
All this makes the code barely readable and hard to remake from scratch.
And a cool fact: use ::type to change the type of a block in Scratchblocks:move (2) steps ::events
snip block lol ::grey
custom block ::custom
(the jittery collision detection problem is still not solved though and we are going a bit off topic.)
Last edited by DNQ_brwn (Feb. 28, 2025 22:15:43)
- DNQ_brwn
-
Scratcher
30 posts
collision works, unless you both keep sliding into the wall while walk towards the wall, please help.
Bump.
- DNQ_brwn
-
Scratcher
30 posts
collision works, unless you both keep sliding into the wall while walk towards the wall, please help.
Bump
- OrangeFlyingCat
-
Scratcher
100+ posts
collision works, unless you both keep sliding into the wall while walk towards the wall, please help.
Bump.
BumpHave you fixed this?
- DNQ_brwn
-
Scratcher
30 posts
collision works, unless you both keep sliding into the wall while walk towards the wall, please help.
No I cannot even fix the collision myself because,Bump.BumpHave you fixed this?
1. the way I coded it is to prevent the vertical hitbox from being inside a wall that it cannot move vertically out of, that's for the ground,
2. moving the player out of the wall by negative value without input and repeating it until the player moves out the wall sends the player out of bounds.
this is the only way I know how to do horizontal scrolling collision, by subtracting movement. even if I disable the vertical collision you're in the wall for 5 milliseconds then you slowly move out the wall if you keep sliding and walking into the wall.
- OrangeFlyingCat
-
Scratcher
100+ posts
collision works, unless you both keep sliding into the wall while walk towards the wall, please help.
So, the collisions and movement should work like this (though, most probably, your ones work differently):
switch costume to (Hitbox v) //just a rectangle that somewhat represents the player's size
change [world x v] by (speed x)
position
if <touching (Level v) ?> then
fix collision x
end
change [world y v] by (speed y)
position
if <touching (Level v) ?> then
fix collision y
end
define position
go to x: ((round (world x)) - (round (Camera X))) y: ((round (world y)) - (round (Camera Y)))
define fix collision x
set [i v] to [1]
repeat (5) //checking if we hit just a small step
change [world y v] by (i)
position
if <not <touching (Level v) ?>> then
stop [this script v]
end
change [world y v] by ((-2) * (i))
position
if <not <touching (Level v) ?>> then
stop [this script v]
end
change [world y v] by (i)
change [i v] by (1)
end
position
repeat until <not <touching (Level v) ?>>
if <(speed x) > (0)> then
change [world x v] by (-1)
else
change [world x v] by (1)
end
position
end
set [speed x v] to [0]
define fix collision y
set [i v] to [1]
repeat (5) //checking if we hit just a small step
change [world x v] by (i)
position
if <not <touching (Level v) ?>> then
stop [this script v]
end
change [world x v] by ((-2) * (i))
position
if <not <touching (Level v) ?>> then
stop [this script v]
end
change [world x v] by (i)
change [i v] by (1)
end
position
repeat until <not <touching (Level v) ?>>
if <(speed y) > (0)> then
change [world y v] by (-1)
else
change [world y v] by (1)
end
position
end
set [speed y v] to [0]
- DNQ_brwn
-
Scratcher
30 posts
collision works, unless you both keep sliding into the wall while walk towards the wall, please help.
.
https://scratch.mit.edu/projects/1137901998/editor
So, the collisions and movement should work like this (though, most probably, your ones work differently):It does do it's job, but when it's done without screen refresh,you walk straight into the wall, It still pushes the player too far off the map.switch costume to (Hitbox v) //just a rectangle that somewhat represents the player's size
change [world x v] by (speed x)
position
if <touching (Level v) ?> then
fix collision x
end
change [world y v] by (speed y)
position
if <touching (Level v) ?> then
fix collision y
end
define position
go to x: ((round (world x)) - (round (Camera X))) y: ((round (world y)) - (round (Camera Y)))
define fix collision x
set [i v] to [1]
repeat (5) //checking if we hit just a small step
change [world y v] by (i)
position
if <not <touching (Level v) ?>> then
stop [this script v]
end
change [world y v] by ((-2) * (i))
position
if <not <touching (Level v) ?>> then
stop [this script v]
end
change [world y v] by (i)
change [i v] by (1)
end
position
repeat until <not <touching (Level v) ?>>
if <(speed x) > (0)> then
change [world x v] by (-1)
else
change [world x v] by (1)
end
position
end
set [speed x v] to [0]
define fix collision y
set [i v] to [1]
repeat (5) //checking if we hit just a small step
change [world x v] by (i)
position
if <not <touching (Level v) ?>> then
stop [this script v]
end
change [world x v] by ((-2) * (i))
position
if <not <touching (Level v) ?>> then
stop [this script v]
end
change [world x v] by (i)
change [i v] by (1)
end
position
repeat until <not <touching (Level v) ?>>
if <(speed y) > (0)> then
change [world y v] by (-1)
else
change [world y v] by (1)
end
position
end
set [speed y v] to [0]

https://scratch.mit.edu/projects/1137901998/editor
- OrangeFlyingCat
-
Scratcher
100+ posts
collision works, unless you both keep sliding into the wall while walk towards the wall, please help.
.The top scripts should not be done without screen refreshSo, the collisions and movement should work like this (though, most probably, your ones work differently):It does do it's job, but when it's done without screen refresh,you walk straight into the wall, It still pushes the player too far off the map.switch costume to (Hitbox v) //just a rectangle that somewhat represents the player's size
change [world x v] by (speed x)
position
if <touching (Level v) ?> then
fix collision x
end
change [world y v] by (speed y)
position
if <touching (Level v) ?> then
fix collision y
end
define position
go to x: ((round (world x)) - (round (Camera X))) y: ((round (world y)) - (round (Camera Y)))
define fix collision x
set [i v] to [1]
repeat (5) //checking if we hit just a small step
change [world y v] by (i)
position
if <not <touching (Level v) ?>> then
stop [this script v]
end
change [world y v] by ((-2) * (i))
position
if <not <touching (Level v) ?>> then
stop [this script v]
end
change [world y v] by (i)
change [i v] by (1)
end
position
repeat until <not <touching (Level v) ?>>
if <(speed x) > (0)> then
change [world x v] by (-1)
else
change [world x v] by (1)
end
position
end
set [speed x v] to [0]
define fix collision y
set [i v] to [1]
repeat (5) //checking if we hit just a small step
change [world x v] by (i)
position
if <not <touching (Level v) ?>> then
stop [this script v]
end
change [world x v] by ((-2) * (i))
position
if <not <touching (Level v) ?>> then
stop [this script v]
end
change [world x v] by (i)
change [i v] by (1)
end
position
repeat until <not <touching (Level v) ?>>
if <(speed y) > (0)> then
change [world y v] by (-1)
else
change [world y v] by (1)
end
position
end
set [speed y v] to [0]
https://scratch.mit.edu/projects/1137901998/editor

I'll be sharing a scrolling platformer example soon, I'll give you a link when I will (it's not an advertisement because you can always use TurboWarp to play the project anonymously without giving it a “view”)
- DNQ_brwn
-
Scratcher
30 posts
collision works, unless you both keep sliding into the wall while walk towards the wall, please help.
that's good news..The top scripts should not be done without screen refreshSo, the collisions and movement should work like this (though, most probably, your ones work differently):It does do it's job, but when it's done without screen refresh,you walk straight into the wall, It still pushes the player too far off the map.switch costume to (Hitbox v) //just a rectangle that somewhat represents the player's size
change [world x v] by (speed x)
position
if <touching (Level v) ?> then
fix collision x
end
change [world y v] by (speed y)
position
if <touching (Level v) ?> then
fix collision y
end
define position
go to x: ((round (world x)) - (round (Camera X))) y: ((round (world y)) - (round (Camera Y)))
define fix collision x
set [i v] to [1]
repeat (5) //checking if we hit just a small step
change [world y v] by (i)
position
if <not <touching (Level v) ?>> then
stop [this script v]
end
change [world y v] by ((-2) * (i))
position
if <not <touching (Level v) ?>> then
stop [this script v]
end
change [world y v] by (i)
change [i v] by (1)
end
position
repeat until <not <touching (Level v) ?>>
if <(speed x) > (0)> then
change [world x v] by (-1)
else
change [world x v] by (1)
end
position
end
set [speed x v] to [0]
define fix collision y
set [i v] to [1]
repeat (5) //checking if we hit just a small step
change [world x v] by (i)
position
if <not <touching (Level v) ?>> then
stop [this script v]
end
change [world x v] by ((-2) * (i))
position
if <not <touching (Level v) ?>> then
stop [this script v]
end
change [world x v] by (i)
change [i v] by (1)
end
position
repeat until <not <touching (Level v) ?>>
if <(speed y) > (0)> then
change [world y v] by (-1)
else
change [world y v] by (1)
end
position
end
set [speed y v] to [0]
https://scratch.mit.edu/projects/1137901998/editor
I'll be sharing a scrolling platformer example soon, I'll give you a link when I will (it's not an advertisement because you can always use TurboWarp to play the project anonymously without giving it a “view”)
Last edited by DNQ_brwn (March 3, 2025 18:11:05)
- OrangeFlyingCat
-
Scratcher
100+ posts
collision works, unless you both keep sliding into the wall while walk towards the wall, please help.
Scratch link:
https://scratch.mit.edu/projects/1141999320/
TurboWarp link:
https://turbowarp.org/1141999320
Hope you will not need to redo the whole engine.
https://scratch.mit.edu/projects/1141999320/
TurboWarp link:
https://turbowarp.org/1141999320
Hope you will not need to redo the whole engine.
- DNQ_brwn
-
Scratcher
30 posts
collision works, unless you both keep sliding into the wall while walk towards the wall, please help.
,
Scratch link:Thanks for your help. I really appreciate the dedication to fixing this problem.
https://scratch.mit.edu/projects/1141999320/
TurboWarp link:
https://turbowarp.org/1141999320
Hope you will not need to redo the whole engine.
- Discussion Forums
- » Help with Scripts
-
» collision works, unless you both keep sliding into the wall while walk towards the wall, please help.