Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » my collision system breaks when hitting a corner
- braxlord
-
Scratcher
33 posts
my collision system breaks when hitting a corner
_ https://scratch.mit.edu/projects/1217142255/ _
|_ look at the define tick and define findwalls, and see if there are any issues, because it breaks when the ball is hitting a corner. _|
|_ look at the define tick and define findwalls, and see if there are any issues, because it breaks when the ball is hitting a corner. _|
- PaSc_Clan
-
Scratcher
100+ posts
my collision system breaks when hitting a corner
Is the problem with the cube going back down, and not going through the entire maze?
Last edited by PaSc_Clan (Sept. 16, 2025 14:11:29)
- Whitepatchwastaken
-
Scratcher
100+ posts
my collision system breaks when hitting a corner
If I had to guess, it looks like the problem's stemming from how you're checking the distance to each wall. Specifically, each check doesn't actually reach the corners of the block, so if it's close to a corner it could clip into it and think it's fine one frame, but then on the next frame it moves a little closer to one side of the corner and starts detecting it.
- RokCoder
-
Scratcher
1000+ posts
my collision system breaks when hitting a corner
If you look at the variables at the point where the ball gets stuck, you'll notice that topwall < bottomwall
This is due to your rather unusual collision detection system. Both scanning upwards and downwards have an immediate collision with a wall, so your +/- adjustments equate to the bottom wall being above the top wall. This leads to the code getting stuck in an infinite loop in your tick custom block.
One possible fix, without refactoring a lot of your code, is to check for collisions in the direction that you're moving. E.g. if the ball is moving downwards, only check for collisions against the bottom wall.
And
This is due to your rather unusual collision detection system. Both scanning upwards and downwards have an immediate collision with a wall, so your +/- adjustments equate to the bottom wall being above the top wall. This leads to the code getting stuck in an infinite loop in your tick custom block.
One possible fix, without refactoring a lot of your code, is to check for collisions in the direction that you're moving. E.g. if the ball is moving downwards, only check for collisions against the bottom wall.
repeat until < not <<< (bally) > (topwall) > and <(ballvy) < (0)>> or << (bally) < (bottomwall) > and <(ballvy) > (0)>>>>
And
repeat until < not <<< (ballx) > (rightwall) > and <(ballvx) < (0)>> or << (ballx) < (leftwall) > and <(ballvx) > (0)>>>>
- braxlord
-
Scratcher
33 posts
my collision system breaks when hitting a corner
If you look at the variables at the point where the ball gets stuck, you'll notice that topwall < bottomwallThis did work without any problems! Thx for the help!
This is due to your rather unusual collision detection system. Both scanning upwards and downwards have an immediate collision with a wall, so your +/- adjustments equate to the bottom wall being above the top wall. This leads to the code getting stuck in an infinite loop in your tick custom block.
One possible fix, without refactoring a lot of your code, is to check for collisions in the direction that you're moving. E.g. if the ball is moving downwards, only check for collisions against the bottom wall.repeat until < not <<< (bally) > (topwall) > and <(ballvy) < (0)>> or << (bally) < (bottomwall) > and <(ballvy) > (0)>>>>
Andrepeat until < not <<< (ballx) > (rightwall) > and <(ballvx) < (0)>> or << (ballx) < (leftwall) > and <(ballvx) > (0)>>>>
- Discussion Forums
- » Help with Scripts
-
» my collision system breaks when hitting a corner



