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

Legacy GM Help Completing Enemy Attack Animation

D

dawson2223

Guest
Hey,

I have an enemy attack animation set up and right now it's running if the player is within a certain range to him. My question is how can I have the enemy finish the animation, even if the player runs out of the attacking range?

So if my attack animation is say 10 frames, how do I make it complete all 10 frames before chasing my player again, instead of stopping to chase the player after just a few frames if he gets out of the range?

If this is an easy question I apologize.

Thanks!
 

Soso

Member
Make a variable called

Enemy_state = "normal";

Distance_to_object (obj.player) <= 32 && enemy_state = "normal"
{enemy_state = "attack";}

if enemy_state = "attack"
{sprite_index = spr_enemy_attack;}

if enemy_state = "attack" && image_index = 10
{enemy_state = "normal";}
 
D

dawson2223

Guest
Make a variable called

Enemy_state = "normal";

Distance_to_object (obj.player) <= 32 && enemy_state = "normal"
{enemy_state = "attack";}

if enemy_state = "attack"
{sprite_index = spr_enemy_attack;}

if enemy_state = "attack" && image_index = 10
{enemy_state = "normal";}
I'm using two scripts, an enemy chase and enemy attack script. The scripts didn't like Enemy_state as a local variable so I tried making it a global variable and still no luck :( any ideas?
 
D

dawson2223

Guest
Post your code
Code:
///scr_enemyChase

var dis = point_distance(x,y,obj_player.x,obj_player.y)

if (dis > attackRange)
{
action_potential_step (obj_player.x,obj_player.y,1.5,0)
image_speed = .5

if (obj_player.x > x && obj_player.y = y) // PLAYER ON RIGHT
sprite_index = spr_EnemyRunRight
if (obj_player.x < x && obj_player.y = y) // PLAYER ON LEFT
sprite_index = spr_EnemyRunLeft
if (obj_player.y < y && obj_player.x = x) // PLAYER ON UP
sprite_index = spr_EnemyRunUp
if (obj_player.y > y && obj_player.x = x) // PLAYER ON DOWN
sprite_index = spr_EnemyRunDown
if (obj_player.x > x && obj_player.y > y) // PLAYER ON RIGHT DOWN
{ if (abs(obj_player.x-x > obj_player.y-y)) // MORE ON RIGHT
        sprite_index = spr_EnemyRunRight
  else
        sprite_index = spr_EnemyRunDown
        }

if (obj_player.x < x && obj_player.y > y) // PLAYER ON LEFT DOWN
{ if (abs(x-obj_player.x > obj_player.y-y)) // MORE ON LEFT
        sprite_index = spr_EnemyRunLeft
  else
        sprite_index = spr_EnemyRunDown
        }
        
if (obj_player.x < x && obj_player.y < y) // PLAYER ON LEFT UP
{ if (abs(x-obj_player.x > y-obj_player.y)) // MORE ON LEFT
        sprite_index = spr_EnemyRunLeft
  else
        sprite_index = spr_EnemyRunUp
        }

if (obj_player.x > x && obj_player.y < y) // PLAYER ON RIGHT UP
{ if (abs(obj_player.x-x > y-obj_player.y)) // MORE ON RIGHT
        sprite_index = spr_EnemyRunRight
  else
        sprite_index = spr_EnemyRunUp
        }
}

else if (dis <= attackRange)
{
speed = 0;
state = scr_enemyAttack;
}
Code:
///scr_enemyAttack
var dis = point_distance(x,y,obj_player.x,obj_player.y);

if (dis >= attackRange) {
        state = scr_enemyChase;
        }
else
{

if (obj_player.x > x && obj_player.y = y) // PLAYER ON RIGHT
sprite_index = spr_blondeAttackRight
if (obj_player.x < x && obj_player.y = y) // PLAYER ON LEFT
sprite_index = spr_blondeAttackLeft
if (obj_player.y < y && obj_player.x = x) // PLAYER ON UP
sprite_index = spr_blondeAttackUp
if (obj_player.y > y && obj_player.x = x) // PLAYER ON DOWN
sprite_index = spr_blondeAttackDown
if (obj_player.x > x && obj_player.y > y) // PLAYER ON RIGHT DOWN
{ if (abs(obj_player.x-x > obj_player.y-y)) // MORE ON RIGHT
        sprite_index = spr_blondeAttackRight
  else
        sprite_index = spr_blondeAttackDown
        }

if (obj_player.x < x && obj_player.y > y) // PLAYER ON LEFT DOWN
{ if (abs(x-obj_player.x > obj_player.y-y)) // MORE ON LEFT
        sprite_index = spr_blondeAttackLeft
  else
        sprite_index = spr_blondeAttackDown
        }
        
if (obj_player.x < x && obj_player.y < y) // PLAYER ON LEFT UP
{ if (abs(x-obj_player.x > y-obj_player.y)) // MORE ON LEFT
        sprite_index = spr_blondeAttackLeft
  else
        sprite_index = spr_blondeAttackUp
        }

if (obj_player.x > x && obj_player.y < y) // PLAYER ON RIGHT UP
{ if (abs(obj_player.x-x > y-obj_player.y)) // MORE ON RIGHT
        sprite_index = spr_blondeAttackRight
  else
        sprite_index = spr_blondeAttackUp
        }
}


//Attack Animation
image_speed = 0.5;



//Attack

if (alarm[1] == -1) && global.dodge = 0{
        global.hp -=1;
        global.regen = -300;
        alarm[1] = room_speed/2;
    }
if (alarm[1] == -1) && global.dodge = 1{
        global.hp -=0;
        global.regen = -300;
        alarm[1] = room_speed/2;
    }
 

Soso

Member
Your gonna have to tweak your code
But using image index could work for your attack animation. Theres also an animation end event that can do the same thing

Read about finite state machines though it may help with your project
 
D

dawson2223

Guest
Your gonna have to tweak your code
But using image index could work for your attack animation. Theres also an animation end event that can do the same thing
Read about finite state machines though it may help with your project

Okay thanks!!!
 
Top