• 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!

Fast moving objects sometimes passes through other solid objects

Liv.Somik

Member
So I'm trying to make this top-down mini golf game that doesn't use room physics.

I have these 2 lines of code to bounce my golf ball in the proper direction when colliding with walls. (all set to solid objects)

if place_meeting(x, y, obj_wallshorizontal) {vspeed = vspeed * -1;}
if place_meeting(x, y, obj_wallsvertical) {hspeed = hspeed * -1;}

They work perfectly most of the time, but I noticed that if the ball goes faster, half of the time the ball just goes through the walls like nothing or sometimes even gets stuck inside them. How should I prevent this from happening?
 

Slyddar

Member
If the movement per step of the ball is greater than the width or height of the colliding wall, there are times when it is on one side of the wall on one step, then the next step it will be on the other side, effectively jumping over the wall, as it never technically collided with it.
One way to avoid this is to limit the speed to never be greater than the width or height of a wall.
Another method is you need to do more place_meeting checks at intervals up to the max speed of the ball.
 

GMWolf

aka fel666
Unfortunately GM doesn't offer great tools to deal with this (such a vector collision, or more collision shapes).

On simple fix would be to check for collisions at multiple points along (xprevious, yprevious) (x, y).

Another option is to use collision_line().

Both methods are somewhat inaccurate in different ways, but its probably the best you can do without writing complex collisions detection code.
 
Top