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

attack animation while character or player is moving

X

xCrazyxSinner13x

Guest
i use heartbeast rpg tutorial for attack state but the character stop to play the animation i was if some one can give me a clue to how to get him to attack while moving here is the code for the player
create event obj_player
///Initialize Variable
// The Game main gravity
grav = 1;
// Player main speed
spd = 4;
// Player how high can jump
jspd = 12;
// IF player not moving speed zero
hspd = 0;
// IF player not moving speed zero
vspd = 0;
// Player friction speed
fric = 1;
//variable to double jump the higher the number the more jumps player can do
doublejump = 1;
//wall jump spd away from wall
wjspd=8;
wvspd=1;
//dash state 1 or 0 or true or false
dash_State = false;
//aniamation
image_speed = 0;
//attack = false;
scr_get_input();
state = scr_move_state;

step event obj_player
/// Platfrom physics
scr_get_input();

//camera movement
scr_player_camera_Movement();

//left mouse to shoot
if (mouse_left)
{
// the alarm will tick down tiil zero
alarm[0] = -1 alarm = 10;
}

//meele attack
//if melee_attack_state

if mouse_right and alarm[3]=-1
{
image_index = 0;
image_speed = 0.5;
//image_speed = speed/25;
state = scr_meele_attack_state;
}
script_execute(state);

animation end obj_player
/// change back to move state
if (state == scr_meele_attack_state)
{
state = scr_move_state;
}

here the movement script
///scr_move_state
scr_get_input();
// Check for ground
if (place_meeting(x,y+1,obj_solid))
{
doublejump = 1;
vspd=0;

// Jumping
if (key_jump)
{
vspd = -jspd
}
}

// This is a else statment if the statement above is false then this statement will be true
else
{
//Gravity
if (vspd < 10)
{
vspd += grav;
}
if (keyboard_check_released(vk_space) && vspd <-4)
{
vspd = -4;
}
//checking for doublejump
if (doublejump > 0)
{
if (key_jump)
{
vspd = -jspd;
doublejump -= 1;
}
}
}

///scr_dash_state;
// Dash State standing still
if dash_State
{

// dash speed left
if sprite_index = spr_player_left
{
hspd=spd*-4;

//key_right =0;
}

// dash speed left
if sprite_index = spr_player_right
{
hspd=spd*+4;
}
}
else
{
if key_dash and alarm[2]=-1
{
dash_State=true; // Set to run speed code
alarm[1]=room_speed/30 // How long the dash works
alarm[2]=room_speed*1 // Wait until dash again
}
}


//wall jump right
if(place_meeting(x+1,y,obj_solid) and !place_meeting(x,y+1,obj_solid) and key_jump)
{
vspd = -jspd;
hspd = -wjspd;
doublejump = 1;
}

//wall jump left
if(place_meeting(x-1,y,obj_solid) and !place_meeting(x,y+1,obj_solid) and key_jump)
{
vspd = -jspd;
hspd = +wjspd;
doublejump = 1;

}

//moving right
if(key_right)
{
//sprite moving right the sprite changes to player right sprite
sprite_index = spr_player_right;
image_speed = 0.2;
if(hspd < spd)
{
hspd += fric;
}
else
{
hspd = spd;
}
//dash state while moving right
if dash_State
{
// dash speed right
sprite_index = spr_player_right;
// image_speed=0.2

{
hspd=spd*+7;
}
}
else
{
if key_dash and alarm[2]=-1
{
dash_State=true; // Set to run speed code
alarm[1]=room_speed/30 // How long the dash works
alarm[2]=room_speed*1 // Wait until dash again
}
}
}

//moving left
if(key_left)
{
sprite_index = spr_player_left;
image_speed = 0.2;
if(hspd > -spd)
{
hspd -= fric;
}
else
{
hspd = -spd;
}
//dash state while moving left
if dash_State
{
// dash speed left
if sprite_index = spr_player_left
{
hspd=spd*-7;
}
}
else
{
if key_dash and alarm[2]=-1
{
dash_State=true; // Set to run speed code
alarm[1]=room_speed/30 // How long the dash works
alarm[0]=room_speed*1 // Wait until dash again
}
}
}

//Check for not moving, || means or
if((!key_right && !key_left) || (key_right && key_left))
{
image_speed = 0;
image_index = 0;
if (hspd != 0)
{
if (hspd < 0)
{
hspd +=fric;
}
else
{
hspd -=fric;
}
}
}

//horizontal collision
if (place_meeting(x+hspd,y,obj_solid))
{
while (!place_meeting(x+sign(hspd),y,obj_solid))
{
x+= sign(hspd);
}
hspd = 0;
}

//move horizontally
x += hspd;

// Vertical collisions
if (place_meeting(x,y+vspd,obj_solid))
{
while (!place_meeting(x,y+sign(vspd),obj_solid))
{
y+= sign(vspd);
}
vspd = 0;
}

// Moving vertically
y += vspd;

heres is the attack script
image_speed = 0.5;
//image_speed = speed/25;
switch (sprite_index)
{
case spr_player_right:

sprite_index = spr_player_meele_attack_right;
break;

case spr_player_left:
//do something
sprite_index = spr_player_meele_attack_left;
break;
}
 
X

xCrazyxSinner13x

Guest
ive tried to put this in my attack script it works but there is a problem its glitch because if i hold down left key to move and press the attack key repeatedly then decide to press the right key and the attack key the player will slide in a weird way and be unresponsive for a few seconds.

// Vertical
repeat(abs(vspd)) {
if (!place_meeting(x, y + sign(vspd), obj_solid))
y += sign(vspd);
else {
vspd = 0;
break;
}
}

// Horizontal
repeat(abs(hspd)) {
if (!place_meeting(x + sign(hspd), y, obj_solid))
x += sign(hspd);
else {
hspd = 0;
break;
}
}
 
Top