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

SOLVED State Machine issues

Null-Z

Member
shadow Weirdness .gif
so, I've got a state machine for this shadow biter here but as you can see, it seems to be skipping or going through states too quickly.
GML:
switch (state)
{
    case Shadow_state.Search: {scr_ShadowSearch();}; break;
     case Shadow_state.SeekLeft: {scr_ShadowSeekLeft();}; break;
     case Shadow_state.SeekRight: {scr_ShadowSeekRight();}; break;
     case Shadow_state.Prepare: {scr_ShadowPrepare();}; break;
      case Shadow_state.Attack: {scr_ShadowAttack();}; break;
     case Shadow_state.Recoil: {scr_ShadowRecoil();}; break;
}
Code:
sprite_index = spr_ShadowSearch;
image_speed = 0.1;

if instance_exists(obj_Player)
    {
        if point_distance(x, y, obj_Player.x, obj_Player.y) < 200
            {
                if x >= obj_Player.x
                {
                state = Shadow_state.SeekLeft;
                }
                    else
                {
                  state = Shadow_state.SeekRight; 
                }
            }
    }
Code:
if !place_meeting(x,y,BCH_G)
    {
        hspeed = 0;
        state = Shadow_state.Recoil;
    }
//speed control

if hspeed <= -3
    {
        hspeed = -3
    }
    //Player check
if instance_exists(obj_Player)
    {
        if x > obj_Player.x
            {
             sprite_index = spr_shadowSeekL
            hspeed -= 0.1
            }
    }
if instance_exists(obj_Player)
{
 if x <= obj_Player.x
    {
    hspeed = 0;
     state = Shadow_state.Prepare;
    }
 }
Code:
if !place_meeting(x,y,BCH_G)
    {
        hspeed = 0;
        state = Shadow_state.Recoil;
    }
//speed control

if hspeed >= 3
    {
        hspeed = 3;
    }
    //Player check
if instance_exists(obj_Player)
    {
        if x < obj_Player.x
            {
             sprite_index = spr_ShadowSeekR
            hspeed += 0.1
            }
    }
if instance_exists(obj_Player)
{
 if x >= obj_Player.x
    {
    hspeed = 0;
     state = Shadow_state.Prepare;
    }
 }
Code:
sprite_index = spr_ShadowBiterAtk;
image_speed = 0.1
    
    
    if (image_index+image_speed >= image_number)
{
   state = Shadow_state.Attack;
}
Code:
sprite_index = spr_ShadowBiteDown
image_speed = 0.1;

       if place_meeting(x,y,obj_Player)
        {
            instance_create(obj_Player.x,obj_Player.y,OBJ_PlayerDeath);
            instance_destroy(obj_Player);
        }

if (image_index+image_speed >= image_number)
{
   state = Shadow_state.Recoil;
}
Code:
sprite_index = spr_ShadowBiterIDl
 image_speed = 0.1 
    
      if (image_index+image_speed >= image_number)
{   
  state = Shadow_state.Search;
}
What am I doing wrong?
 

curato

Member
I am not sure what you are asking here. The shadow does seem to follow the player and attack. Is it too aggressive? If so you could always set a wait state to hold it idle for a few seconds before it comes at you again.

Edit Nidoking suggestion too. I missed that. Always good to reset the image_index when you are changing animations.
 
Top