• 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] Wall collision doesn't work properly

607

Member
Hey, I'm stuck at the moment.
I've got this code in my character's step event:
Code:
//Movement
hspeed = v * (keyboard_check(vk_right) - keyboard_check(vk_left))
vspeed = v * (keyboard_check(vk_down) - keyboard_check(vk_up))
   
//Collission
if !hspeed = 0
if !place_free(x+hspeed,y)
{
    if hspeed > 0 move_contact_solid(0,hspeed)
    if hspeed < 0 move_contact_solid(180,-hspeed)
    hspeed = 0
}

if !vspeed = 0
if !place_free(x,y+vspeed)
{
    if vspeed > 0 move_contact_solid(270,vspeed)
    if vspeed < 0 move_contact_solid(90,-vspeed)
    vspeed = 0
}
v is set in the object's create code.
And I've got a solid wall object without any extra code attached to it.

Movement works fine, and colliding from the right and up sides work fine too.
However, if the character comes up from the down or the left side, she goes into and through the wall if she so desires.
I suspect this has got something to do with the hspeed and vspeed being negative, but I wouldn't know what's wrong. I've also tried using 'hspeed' and 'vspeed' instead of '-hspeed' and '-vspeed' for the lines concerned, but that didn't seem to fix it.

Has anyone got any other ideas? :)

 

607

Member
I figured it out, with help of a friend.
It should be 'if vspeed != 0', not 'if !vspeed = 0'. And of course, same for hspeed.
 
Last edited:
Top