#How do I reset||stop Enemy animation state if it misses an attack

12 messages · Page 1 of 1 (latest)

delicate gyro
#

Hello! I am currently working on an enemies attack state however; whenever the enemy attacks it remains at the last frame of the animation. I was wondering how I could check for a collision with an object when the enemy attacks and then reset the enemy(s) state to something else? And, just in case, I did post this in the GM Help tab but I wanted to get as my heads on this as possible.

Enemy attack code beneath

function SLOTHATTACKM(){


EnCombotimer = 60;

if EnCombotimer > 0 {
        EnCombotimer -= 1;
}



//How fast to move
var _spd =  EnemySpeed;

//Dont move while still getting ready to jumo
if (image_index < 2) _spd = 0;

//Freeze animation while in mid-air and also after landing finishes
if (floor(image_index) == 3) || (floor(image_index) == 5) image_speed = 0;

//How far we have to jump
var _distanceToGo = point_distance(x,y,xTo,yTo);

//begin landing end of the animation once we're nearly done
if (_distanceToGo < 160) && (image_index < 5)  image_speed = 1.0;


//Move
if (_distanceToGo > _spd) {
    dir = point_direction(x,y,xTo,yTo);
    hSpeed = lengthdir_x(_spd,dir);
    vSpeed = lengthdir_y(_spd,dir);
    if (hSpeed != 0) image_xscale = sign(hSpeed)
    
    //Commit to move and stop moving if we hit a wall
    if (EnemyTileCollision() == true) && (place_meeting(x, y, obj_Player)) {
        xTo = x;
        yTo = y;
            stateTarget = ENEMYSTATE.CHASE;
        stateWaitDuration = 10;
        state = ENEMYSTATE.WAIT;
    }
}else {
    if(floor(image_index) == 5) {
    x = xTo;
    y = yTo;
        stateTarget = ENEMYSTATE.CHASE;
        stateWaitDuration = 15;
        state = ENEMYSTATE.WAIT;
    }
}
}
ashen solar
#

if (EnemyTileCollision() == true) && (place_meeting(x, y, obj_Player))
don't you mean to use an OR here instead of AND?

#

weird use of () by the way

#

from what I can see you're probably always entering the else case

#

which probably makes your character hold the sprite frame for another 15 game frames

delicate gyro
ashen solar
#

if you're still needing help with this

#

I say you just need to make better use of state machines and better visualize what you want to happen

#

if the enemy is in its chase state, it's just moving towards the player until in range, right?
At the moment this enemy meets the criteria of being able to attack, it switches to atttack

#

in the attack state all the code your enemy needs to run is
"did I finiish my animaton" or "did I hit the player" or "did I hit the wall" or "did I get hit during my animation", whatever you're planning for the game

#

if your enemy passes the check of finishing the animation, it goes to a diifferent state just for waiting a little before moving again, which also should contain code for "did I get hit"

#

and THEN it goes back to chase