Android collision checking problem

M

m_brudi

Guest
hey there
i know its probably super simple or even stupid question but i cant figure it out on my own
so im spawning enemies and platforms randomly in front of my player (he's running to the right)
and i cant fix this issue that enemies sometimes stands on only one foot.
i wanna check if only one foot touches the ground and if so, move the object so its standing properly.
thanks guys
collision.jpg
 

Roderick

Member
Make the mask a rectangle that covers both feet, but no extra width. In the creation code, add the following, modified as necessary for your object names:

Code:
if (!place_meeting(x, y + 1, obj_floor))
 {instance_destroy();} // This destroys the instance if neither foot is on the floor

if (!position_meeting(bbox_left, bbox_bottom + 1, obj_floor) && position_meeting(bbox_right, bbox_bottom + 1, obj_floor)) // if right foot is on ground but left foot is not
{
 while (!position_meeting(bbox_left, bbox_bottom + 1, obj_floor))
 {x++;} // Move right one pixel at a time until both feet are on the floor.
}
Your screenshot only shows enemies with the left foot hanging off the edge. If they spawn on the other side too, duplicate the second block, but reverse everything so that it checks for a floating right foot nd moves left if necessary.
 
M

m_brudi

Guest
Make the mask a rectangle that covers both feet, but no extra width. In the creation code, add the following, modified as necessary for your object names:

Code:
if (!place_meeting(x, y + 1, obj_floor))
 {instance_destroy();} // This destroys the instance if neither foot is on the floor

if (!position_meeting(bbox_left, bbox_bottom + 1, obj_floor) && position_meeting(bbox_right, bbox_bottom + 1, obj_floor)) // if right foot is on ground but left foot is not
{
 while (!position_meeting(bbox_left, bbox_bottom + 1, obj_floor))
 {x++;} // Move right one pixel at a time until both feet are on the floor.
}
Your screenshot only shows enemies with the left foot hanging off the edge. If they spawn on the other side too, duplicate the second block, but reverse everything so that it checks for a floating right foot nd moves left if necessary.
o man thank you thats exactly what i was looking for! Thanks!
 
Top