Legacy GM help with collison

Hello all am a noob first off so any help is appreciated but I am having an issue where the enemy is getting stuck on the floor and im not sure why. my theory is that it may have to do with the origin but i have tried one in the middle. and at the base of the sprite with no luck.
GML:
/// moving and animation collision
//horizontal collision
hsp= dir* movespeed;
vsp += grav;
if(place_meeting(x+hsp,y,ground))
{
while(!place_meeting(x+sign(hsp),y,ground))
{
x+=sign(hsp);
}
hsp=0;
dir*=-1;
}
x+=hsp;
//vertical collision
if(place_meeting(x,y+vsp,ground))
{
while(!place_meeting(x,y+sign(vsp),ground))
{
y+=sign(vsp);
}
vsp=0;
}
y+=vsp;

if(place_meeting(x+hsp,y,obj_crate))
{
while(!place_meeting(x+sign(hsp),y,obj_crate))
{
x+=sign(hsp);
}
hsp=0;
dir*=-1;
}
x+=hsp;
//vertical collision
if(place_meeting(x,y+vsp,obj_crate))
{
while(!place_meeting(x,y+sign(vsp),obj_crate))
{
y+=sign(vsp);
}
vsp=0;
}
y+=vsp;


if (movespeed!=0)
{
sprite_index= run_test;
image_xscale=1;
image_speed=0.5;

}
 

Nidoking

Member
What matters is that the origin and bounding box of all of the sprites you use is the same. It doesn't matter what they are, as long as they all match. But you're doing two vertical collisions serially - first with ground, and then with obj_crate. You can't do that. One or the other, or do them both in a single pass. Ideally, make a single parent object for everything you want to collide with.
 

woods

Member
the origin of the sprite shouldn't really matter.. my thought on that is the collision check takes the whole sprite (or mask) into the equation.

what happens if you change those "while" to "if"?

from the manual..
As long as the expression is true, the statement (which can also be a code block) is executed. Be careful with your while loops! You can easily make infinite loops, in which case your game will hang and not react to any user input anymore. Below you can find an example of a typical way to use "while":

from what i remmber somewhere in these forums , somebody said something about things not responding while the "while" is happening


shot in the dark ;o)
im not tooo familiar with how while loops work
 
Top