H
HalfSquat
Guest
I have some code in a step event for my character for colliding with some platforms. The vertical collision seems to work okay, although the character seems to land at random elevations on the platform. I can't seem to get the horizontal collision to work for when the character walks straight into a platform. Also, the character will also float in midair if even the top of him is overlapping with a platform. I can't seem to find a way to check for literal pixel-perfect collision from every direction, is that somehow possible?
Code:
//collision with platforms
//vertical collision
if place_meeting(x,y,obj_ground) && hp > 0 || place_meeting(x,y + vspeed,obj_platform) && hp > 0
{
vspeed = 0
sprite_index = spr_idle
if keyboard_check_pressed(vk_space) //press space to jump (works fine)
{
vspeed = -jspeed;
sprite_index = spr_jump
}
}else{
if (vspeed < grav) && !place_meeting(x,y, obj_ground) || (vspeed < grav) && !place_meeting(x,y, obj_platform){
vspeed += grav
sprite_index = spr_jump
}else if (vspeed < grav) && place_meeting(x,y, obj_ground) || (vspeed < grav) && place_meeting(x,y, obj_platform)
{
vspeed = 0
}
}
//horizontal collision with platforms (doesn't work)
if place_meeting(x + hspeed,y,obj_platform) && hp > 0
{
hspeed = 0
}