607
Member
Hey, I'm stuck at the moment.
I've got this code in my character's step event:
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?
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
}
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?