T
TheSandwiche
Guest
I've been handling my player's different attacks with a state machine, but I've encountered a recurring issue where if the player initiates an attack in midair at a certain close distance from the ground, the player object is destroyed and their hurtbox is left behind and it's occurring before a hitbox is generated on image_index 3. I've verified that the object is being destroyed and not just passing through the ground or having a weird issue with it's alpha value. 90% of the time when a player does a mid-air attack and lands on the ground mid-animation, it just cancels the animation, destroys the invisible hitbox, and the player transitions back to their normal 'free' state, but the other 10% of the time this bug occurs. I've already searched the forums with no luck. Any ideas?
I've posted the code for the mid-air attack state where I think the issue is coming from below:
I've posted the code for the mid-air attack state where I think the issue is coming from below:
Code:
vsp = vsp + grv;
var move = key_Right - key_Left;
hsp = walksp * move;
if(place_meeting(x+hsp, y, oWall))
{
hsp = 0;
}
y = y + vsp;
x = x + hsp;
if (facingRight)
{
face_Direction = 1;
facingLeft = 0;
} else if (facingLeft)
{
face_Direction = -1;
facingRight = 0;
}
if (vsp < 0) && (!key_Jump_Held) {
vsp = vsp + 0.6;
}
//Start of the attack
if (sprite_index != Player_AirAttack_Right)
{
sprite_index = Player_AirAttack_Right;
image_index = 0;
ds_list_clear(hitByAttack);
}
if (hitBoxCount < 1 && image_index >= 2)
{
hitbox = hitbox_create(30, 40, 10, -21, 180, 1, 1);
hitBoxCount = 1;
}
var hitByAttackNow = ds_list_create();
if(hitbox != -1){
with(hitbox){
x = other.x + xOffset;
y = other.y + yOffset;
mask_index = Hitbox;
var hits = instance_place_list(x,y, oEnemies, hitByAttackNow, false);
if (hits > 0)
{
for (var i = 0; i < hits; i++)
{
var hitID = hitByAttackNow[|i];
if (ds_list_find_index(hitByAttack,hitID) == -1)
{
//then add it to the list
ds_list_add(hitByAttack,hitID);
with (hitID)
{
show_debug_message("Collision detected");
HP = HP - 1;
}
}
}
}
}
}
if(place_meeting(x, y+vsp, oWall) && vsp > 0)
{
vsp = 0;
grv = 0;
sprite_index = Player_Idle_Right;
state = PLAYERSTATE.FREE;
if (hitbox){
instance_destroy(hitbox);
hitBoxCount = 0;
}
} else if (place_meeting(x, y+vsp, oWall) && vsp <=0){
vsp = 0.1 + grv;
}
ds_list_destroy(hitByAttackNow);
mask_index = Player_Idle_Right;
if (animation_end())
{
sprite_index = Player_Fall_Right;
state = PLAYERSTATE.FREE;
mask_index = Player_Idle_Right;
instance_destroy(hitbox);
hitBoxCount = 0;
}