Having a problem with attacking code

G

Gowford

Guest
Hello ! first of all i want to just tell my problem and what it is .
it's not really something i'm too familiar with but it's something i did just today and it works fine if you don't take into account the massive bug that happens .
the bug is that when you attack , the character stops to attack , but the problem is that if you attack right after you take damage you get launched accross the room until you either hit an solid object or the dangerous water hazard .
here's the code i use for both the attacking part (so it recognizes that it's attacking) and the movement code.(if needed i WILL give out the friction code if needed , because there is one , the problem is i didn't do this , my friend did , so the friction is something i don't mess around with because i dunno how to turn it back on
//LR movement
if (!attacking){
if(sprite_index!=spr_roll){
move = key_left+key_right;
hsp = move * movespeed ;
if(hsp!=0){
if(alarm[2]!=-1){
sprite_index=spr_idle;
alarm[2]=-1;
}
}
}
}
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
//Attacking recognition
if(sprite_index==spr_attack||sprite_index==spr_attack2||sprite_index=spr_attack3){
if(!attacking)
attacking=true
}else{
attacking = false}
 

Jakylgamer

Member
to avoid these types of problems id recommend a state system (FSM)
this way only certain actions can be performed in each state.
simple example:
Code:
switch(my_state) {
   case state.normal :
      //movement code , this is the normal state of the player were most actions can be performed
      if key_attack {
         my_state = state.attacking;
      }
   break;

   case state.attacking :
      //attack animations / sprite changes
   break;

   case state.take_damage :
      //cant move or do anything while in this state
   break;
}
 
G

Gowford

Guest
weeeeell i don't know how to do state events , altough i HAVE separated multiple actions in different parts of an script i have no idea how to make the rest .
 
Top