enemy object doesn't go to edge of left side of platform but goes the whole way to 1/2 a sprite off the right!

Twisty

Member
GML:
hsp = dir * movespeed;
vsp += grav;

// H Collisions
if( place_meeting(x + hsp, y, obj_wall) ){
    while( !place_meeting( x + sign(hsp), y, obj_wall ) )
    {
        x += sign(hsp);
    }
     hsp = 0;
  
   dir *= -1;
  
}
x += hsp;

// V Collisions
if( place_meeting(x, y + vsp, obj_wall) )
{
    while( !place_meeting( x, y + sign(vsp), obj_wall ) )
      {  y += sign(vsp); }
        
   vsp = 0;
  if (fearh) && (!position_meeting(x+(sprite_width/2*sign(dir)), bbox_bottom + 8,obj_wall)) {
   dir *=-1;
}
}
y += vsp;

// enenmy
if (place_meeting(x,y,obj_player))
{
    if (obj_player.y < y -16)
    {
        with (obj_player) vsp = -jumpspeed;
        instance_destroy();
    }
    else
    {
        game_restart();
    }
}
 

saffeine

Member
if i'm right in thinking that you mean the object turns around at the wrong time, try replacing:
GML:
( !position_meeting( x + ( sprite_width / 2 * sign(dir) ), bbox_bottom + 8, obj_wall ) )
with
GML:
( !position_meeting( x + ( sprite_width / 2 ) + ( sprite_width / 2 * sign(dir) ), bbox_bottom + 8, obj_wall ) )
i get the feeling your sprite origin is not set to the center, and position_meeting checks a single point if i remember correctly.
what's happening if this is the case is that you're checking half of the sprite width to the left of the object ( which is floating space to the left ), and half of the sprite width to the right ( which is just halfway into the object ).
alternatively you could just set the sprite's x origin to the middle of the sprite, but if you already have a lot of code that accounts for the x, y being in the top left, then it'll require updating all of that too.
 
Last edited:

Twisty

Member
[SOLVED!]
THANKS SAFFEINE I CAN ALWAYS COUNT ON YOU. YOUR ARE THE BEST PROGRAMMER EVER HAHA!

if i'm right in thinking that you mean the object turns around at the wrong time, try replacing:
GML:
( !position_meeting( x + ( sprite_width / 2 * sign(dir) ), bbox_bottom + 8, obj_wall ) )
with
GML:
( !position_meeting( x + ( sprite_width / 2 ) + ( sprite_width / 2 * sign(dir) ), bbox_bottom + 8, obj_wall ) )
i get the feeling your sprite origin is not set to the center, and position_meeting checks a single point if i remember correctly.
what's happening if this is the case is that you're checking half of the sprite width to the left of the object ( which is floating space to the left ), and half of the sprite width to the right ( which is just halfway into the object ).
alternatively you could just set the sprite's x origin to the middle of the sprite, but if you already have a lot of code that accounts for the x, y being in the top left, then it'll require updating all of that too.
 
Top