• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

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!

T

Twisty

Guest
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:
T

Twisty

Guest
[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.
 
T

Twisty

Guest
Why do you have dir*= -1 in the horizontal collision?

What sort of platform game are you making?

Can you provide more details.
I was making a platformer however no need to worry saffiene has solved the issue :) thanks anyway for replying
 
Top