K
Kotic
Guest
Im currently having trouble getting my character to attack while he is moving.
1. I can get him to move and attack separately
2. I can get him to start the attack animation and move while the animation is going
but I CANT get him to start the attack animation while mid movement, and after I stop moving it takes a couple seconds before it lets me attack after standing still.
Sorry for my redundant code lines and messiness. Any tips and help for coding in gml and organization is appreciated.
This is in my step for my character for swapping states, on creation, moving state is default. using enum in creation of room.
Moving script
and Attacking script
Gif of what the code does
https://gyazo.com/23c1f6a6615bfc57e27d48aa8600155d
1. I can get him to move and attack separately
2. I can get him to start the attack animation and move while the animation is going
but I CANT get him to start the attack animation while mid movement, and after I stop moving it takes a couple seconds before it lets me attack after standing still.
Sorry for my redundant code lines and messiness. Any tips and help for coding in gml and organization is appreciated.
This is in my step for my character for swapping states, on creation, moving state is default. using enum in creation of room.
Code:
switch (states)
{
case states.attacking: scr_attacking(); break;
case states.moving: scr_moving(); break;
}
Code:
var dir = point_direction(x,y,mouse_x,mouse_y); //variable to point character at mouse area
max_speed = 8 //player speed
image_speed = 0 //no animation while standing still
if (speed > max_speed) { speed = max_speed; } //max speed to try and stop fast diag move
if mouse_check_button_pressed(mb_left) //attack button to change states and run script
{
states = states.attacking
}
//4 directions that determine which sprite to use
if(dir > 45 && dir <= 135){
if (sprite_index!=Spr_darkelfwu) image_index = 0;
sprite_index = Spr_darkelfwu;
}
if(dir > 135 && dir <= 225){
if (sprite_index!=Spr_darkelfwl) image_index = 0;
sprite_index = Spr_darkelfwl;
}
if(dir > 225 && dir <= 315){
if (sprite_index!=Spr_darkelfwd) image_index = 0;
sprite_index = Spr_darkelfwd;
}
if(dir > 315 || dir <= 45){
if (sprite_index!=Spr_darkelfwr) image_index = 0;
sprite_index = Spr_darkelfwr;
}
//movement
if (keyboard_check(ord('D')))
{
image_speed = 10
x += 8;
}
if (keyboard_check(ord('A')))
{
image_speed = 10
x -= 8;
}
if (keyboard_check(ord('W')))
{
image_speed = 10
y -= 8;
}
if (keyboard_check(ord('S')))
{
image_speed = 10
y += 8;
}
Code:
max_speed = 8
if (speed > max_speed) { speed = max_speed; }
image_speed = 0.5
dir = point_direction(x,y,mouse_x,mouse_y);
if(dir > 45 && dir <= 135){
if (sprite_index!=Spr_darkelfau) image_index = 0;
sprite_index = Spr_darkelfau;
}
if(dir > 135 && dir <= 225){
if (sprite_index!=Spr_darkelfal) image_index = 0;
sprite_index = Spr_darkelfal;
}
if(dir > 225 && dir <= 315){
if (sprite_index!=Spr_darkelfad) image_index = 0;
sprite_index = Spr_darkelfad;
}
if(dir > 315 || dir <= 45){
if (sprite_index!=Spr_darkelfar) image_index = 0;
sprite_index = Spr_darkelfar;
}
if (keyboard_check(ord('D')))
{
x += 8;
}
if (keyboard_check(ord('A')))
{
x -= 8;
}
if (keyboard_check(ord('W')))
{
y -= 8;
}
if (keyboard_check(ord('S')))
{
y += 8;
}
if image_index = 5
{
states = states.moving
}
https://gyazo.com/23c1f6a6615bfc57e27d48aa8600155d