E
emiran
Guest
I want the enemy ai to follow the player until the position it can hit but while the player is heading rights it works but unfortunately it doesn't function while heading left.
here is my code:
if State == enemyState.Playerseen{
if (can_see == true){
var lastPlayerPosition = inst.x
if instance_exists(inst){
var distance = point_distance(x,y,inst.x,y);
image_xscale = sign(MeleeCombatPlayer.x-x);
if image_xscale == 0 image_xscale = 1;
if (abs(distance)>30){
var Path = path_add();
mp_linear_path_object(Path,lastPlayerPosition,y,4,oWall);
path_start(Path,image_xscale *walksp,path_action_stop,false);
sprite_index = sSkeletonWalk;
State = enemyState.Playerseen;
//move_towards_point(lastPlayerPosition+(image_xscale * 70),y,walksp);
//sprite_index = sSkeletonWalk;
}
else if (abs(distance) <= 30){
path_end();
State = enemyState.Attack;
}
}
}
}
if State == enemyState.Attack{
sprite_index = sSkeletonAttack;
if (image_index > image_number - 1){
var distance = point_distance(x,y,MeleeCombatPlayer.x,MeleeCombatPlayer.y);
if (abs(distance)>30) State = enemyState.Playerseen;
if (abs(distance) <=30) State = enemyState.Attack;
}
}
here is my code:
if State == enemyState.Playerseen{
if (can_see == true){
var lastPlayerPosition = inst.x
if instance_exists(inst){
var distance = point_distance(x,y,inst.x,y);
image_xscale = sign(MeleeCombatPlayer.x-x);
if image_xscale == 0 image_xscale = 1;
if (abs(distance)>30){
var Path = path_add();
mp_linear_path_object(Path,lastPlayerPosition,y,4,oWall);
path_start(Path,image_xscale *walksp,path_action_stop,false);
sprite_index = sSkeletonWalk;
State = enemyState.Playerseen;
//move_towards_point(lastPlayerPosition+(image_xscale * 70),y,walksp);
//sprite_index = sSkeletonWalk;
}
else if (abs(distance) <= 30){
path_end();
State = enemyState.Attack;
}
}
}
}
if State == enemyState.Attack{
sprite_index = sSkeletonAttack;
if (image_index > image_number - 1){
var distance = point_distance(x,y,MeleeCombatPlayer.x,MeleeCombatPlayer.y);
if (abs(distance)>30) State = enemyState.Playerseen;
if (abs(distance) <=30) State = enemyState.Attack;
}
}