• 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!

Enemty Horizontal Collision not working

Hello guys, I'm working on a platformer but it seems that enemies' horizontal collision is not working.
I'm using this code in the step event:
///h collision
if (place_meeting(x+hsp,y,oSolid))
{
while (!place_meeting(x+sign(hsp),y,oSolid))
{
x = x + sign(hsp);
}
hsp = -hsp;
}

x = x + hsp;

///vert collision
if (place_meeting(x,y+vsp,oSolid))
{
while (!place_meeting(x,y+sign(vsp),oSolid))
{
y += sign(vsp);
}
vsp = 0;
}


y += vsp;


///move
{
move_towards_point(oDrifter.x,oDrifter.y,walkspd);
}


(oDrifter being the player)
 

TsukaYuriko

☄️
Forum Staff
Moderator
You posted two different methods of movement. One moves according to hsp and vsp, turns around when it collides horizontally and stops when hitting something vertically, while the other moves directly towards oDrifter by manipulating direction and speed regardless of the other method of movement.

Are you using both in the same object and expecting them to work alongside each other? Because these won't, as they operate based on entirely different principles and actively interfere with each other in their method of applying movement, as you can see.
 

TsukaYuriko

☄️
Forum Staff
Moderator
So what should happen when you follow the thing but run into a wall horizontally? You can't both be moving straight towards something and turning around when you collide with something. As in, you can, but that's going look more like a jackhammer than anything else as it'll be constantly walking in and out of walls in case the second portion triggers.

I have this weird feeling that you copied code from two different sources without really checking if they fit together... is that anywhere close to the truth?
 
Top