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

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.
 
S

spoonsinbunnies

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

2dgeminis

Member
A suggestion, if the enemy does not jump or fall from the platforms, eliminates the part of the code that has to do with gravity and vertical collision..... one more suggestion is that you use the player's object as a basis to create the physics of the enemies.
 
Top