GML My enemies are stuck in the ground (SOLVED)

V

Vincemon

Guest
Hello! ;3

I'm working on a 2D-Platformer and I've created an enemy object. They can be defeated and they could walk from wall to wall. But they don't. When they collide with the ground they turn left and right quickly. And I don't know why.


This is my code in the Step event:

vsp = vsp + grv

//HORIZONTAL COLLISION

if place_meeting(x+hsp,y,oWall)

{

while (!place_meeting(x+sign(hsp),y,oWall))

{

x = x + sign(hsp);

}

hsp = -hsp

}

x = x + hsp;

//VERTICAL COLLISION

if place_meeting(x,y+vsp,oWall)

{

while (!place_meeting(x,y+sign(vsp),oWall))

{

y = y + sign(vsp);

}

vsp = 0

}

y = y + vsp;

And in the Create event:

walksp = 3;

hsp = walksp;

vsp = 0;

grv = 0.4;

Please help! Why are they stuck and how can I fix this? Please comment if you have any questions. I can send more Information if needed
 

CloseRange

Member
I put all the code you gave in a fresh project and it worked just fine. This means something else is happening. Give the rest of the code for the enemy.
There is a fair chance it has to do with the sprite's mask.
 
try changing the place meeting for horizontal to y-1 chances are your enemy is one pixel inside the ground or so so it detects the floor when looking for walls
 

WillB777

Member
How did you fix this? I am having the same problem. Please help with the enemy stuck in the ground, it's so annoying. nvm i got it.
 
Last edited:
Top