• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

SOLVED Problem colision with walls sometimes bugged.

rytan451

Member
Hi, kindly put the code within code boxes, not screenshots. It's a real pain if I have to type out your code to test.

That aside, the symptoms of the bug seem familiar. After the ball hits the boundary, you should move it such that it no longer hits the boundary. Otherwise, the hspeed or vspeed will negate again, moving the ball further out, then on the next step negate again, going further in, and over time making no net progress.
 
Hi, kindly put the code within code boxes, not screenshots. It's a real pain if I have to type out your code to test.

That aside, the symptoms of the bug seem familiar. After the ball hits the boundary, you should move it such that it no longer hits the boundary. Otherwise, the hspeed or vspee
Hi, kindly put the code within code boxes, not screenshots. It's a real pain if I have to type out your code to test.

That aside, the symptoms of the bug seem familiar. After the ball hits the boundary, you should move it such that it no longer hits the boundary. Otherwise, the hspeed or vspeed will negate again, moving the ball further out, then on the next step negate again, going further in, and over time making no net progress.
First of all, sorry, I'm new in the forum and I don't know how to put the code in any other way yet, sorry for that

Yes i think is what you said about that vspeed and hspeed is going from 1 to -1 al the time when the bug occours, how can I make the ball no longer hit the boundary?
 
L

LunaNightshade

Guest
An easy way would be to simply adjust the position slightly, so that it is guaranteed out of the border.
 
Alerternatively, you could handle the boundary intersection differently for the left and right side:

GML:
if (bbox_left < 0) {
    hspeed = abs(hspeed);
} else if (box_right > room_width) {
    hspeed = -abs(hspeed);
}
// Or in one line like this:
if (bbox_left < 0 or bbox_right> room_width) {
    hspeed = abs(hspeed)*sign(room_width/2 - x);
}
To explain what happens here:
With abs() you remove the sign of the hspeed, and then you can set it specifically depending on which side of the room the ball is located.
sign(room_width/2 - x) evaluates to either -1 or 1, depending on which side of the middle of the room the ball is (or 0 if it's exactly in the middle).
 
Alerternatively, you could handle the boundary intersection differently for the left and right side:

GML:
if (bbox_left < 0) {
    hspeed = abs(hspeed);
} else if (box_right > room_width) {
    hspeed = -abs(hspeed);
}
// Or in one line like this:
if (bbox_left < 0 or bbox_right> room_width) {
    hspeed = abs(hspeed)*sign(room_width/2 - x);
}
To explain what happens here:
With abs() you remove the sign of the hspeed, and then you can set it specifically depending on which side of the room the ball is located.
sign(room_width/2 - x) evaluates to either -1 or 1, depending on which side of the middle of the room the ball is (or 0 if it's exactly in the middle).
okay I will try to implement this and check if the bug stills up thank you very much!!
 
Top