S
Sroft
Guest
Thank you for taking time out of your day to help me!
Ok, I have this code for when I want my enemy to chase the player
OEnemy step-
vsp = vsp + grv;
//Enemys state
switch (Enemy_State)//edventually put this into script
{
case ENEMYSTATES.IDLE:
EnemyIdle();
break;
case ENEMYSTATES.CHASE:
EnemyChase();
Break;
}
//Horizontal Collision
if (place_meeting(x+hsp,y,WObject))
{
while (!place_meeting(x+sign(hsp),y,WObject))
{
x = x + sign(hsp);
}
hsp = -hsp;
}
x = x + hsp;
//Vertical Collision
if (place_meeting(x,y+vsp,WObject))
{
while (!place_meeting(x,y+sign(vsp),WObject))
{
y = y + sign(vsp);
}
vsp = 0;
}
y = y + vsp;
//Animation
if (!place_meeting(x,y+1,WObject))
{
sprite_index = EnemyA;
image_speed = 20;
if (sign(vsp) > 20) image_index = 1; else image_index = 1;
}
else
{
image_speed = 1;
if (hsp == 0)
{
sprite_index = Enemy
}
else
{
sprite_index = EnemyR;
}
}
if (hsp != 0) image_xscale = sign(hsp);
EnemyIdle();-
hsp = 0;
vsp = (min(7, vsp + 0.05))
if (distance_to_object(PObject) < 200)
{
Enemy_State = ENEMYSTATES.CHASE
}
EnemyChase();-
if (point_distance(x, y, PObject.x, PObject.y) > 42)
dir = sign(PObject.x -x);
hsp = dir * 10;
vsp = (min(7, vsp + 0.05));
if(distance_to_object(PObject) < 300)
{
Enemy_State = ENEMYSTATES.IDLE
}
The main problem I am having is when the enemies chase you the animation for their run and their idle animation keeps flipping back and forth when they are running at you if anyone has a solution to this I would be utmost grateful.
Sincere-A Newbie Programmer,
thank you
Ok, I have this code for when I want my enemy to chase the player
OEnemy step-
vsp = vsp + grv;
//Enemys state
switch (Enemy_State)//edventually put this into script
{
case ENEMYSTATES.IDLE:
EnemyIdle();
break;
case ENEMYSTATES.CHASE:
EnemyChase();
Break;
}
//Horizontal Collision
if (place_meeting(x+hsp,y,WObject))
{
while (!place_meeting(x+sign(hsp),y,WObject))
{
x = x + sign(hsp);
}
hsp = -hsp;
}
x = x + hsp;
//Vertical Collision
if (place_meeting(x,y+vsp,WObject))
{
while (!place_meeting(x,y+sign(vsp),WObject))
{
y = y + sign(vsp);
}
vsp = 0;
}
y = y + vsp;
//Animation
if (!place_meeting(x,y+1,WObject))
{
sprite_index = EnemyA;
image_speed = 20;
if (sign(vsp) > 20) image_index = 1; else image_index = 1;
}
else
{
image_speed = 1;
if (hsp == 0)
{
sprite_index = Enemy
}
else
{
sprite_index = EnemyR;
}
}
if (hsp != 0) image_xscale = sign(hsp);
EnemyIdle();-
hsp = 0;
vsp = (min(7, vsp + 0.05))
if (distance_to_object(PObject) < 200)
{
Enemy_State = ENEMYSTATES.CHASE
}
EnemyChase();-
if (point_distance(x, y, PObject.x, PObject.y) > 42)
dir = sign(PObject.x -x);
hsp = dir * 10;
vsp = (min(7, vsp + 0.05));
if(distance_to_object(PObject) < 300)
{
Enemy_State = ENEMYSTATES.IDLE
}
The main problem I am having is when the enemies chase you the animation for their run and their idle animation keeps flipping back and forth when they are running at you if anyone has a solution to this I would be utmost grateful.
Sincere-A Newbie Programmer,
thank you