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

Basic collision code for moving walls

E

Electrino

Guest
Hi,

I was making a PacMan style game but where the walls move vertically and horizontally and I've ran into a few problems with the basic collision code I was using.
Here's the code I used:

for movement I used the basic vspeed and hspeed and the wall objects are checked solid...for the collision detection I used the following in obj_player's step:
Code:
if hspeed !=0
if !place_free(x+hspeed,y)
{
      if hspeed>0 move_contact_solid(0,hspeed)
      if hspeed<0 move_contatct)solid(180,-hspeed)
     hspeed=0
}

if vspeed!=0
if !place_free(x+hspeed,y+vspeed)
{
      if vspeed>0 move_contact_solid(270,vspeed)
      if vspeed<0 move_contatct)solid(90,-vspeed)
     vspeed=0
}
This code works fine as long as the walls are static... But once they start moving the obj_player can either stop the movement of the walls by touching them (this only happens sometimes!?) or can clip inside the wall (if the wall collides with obj_player).
Any suggestions on how I'd improve this code?
 

Roderick

Member
Before the wall moves, it needs to check for a collision, just like your player object does. Then, it needs to either not move, or push the player, as appropriate .
 
Top