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