#Weapon firing when dead

33 messages · Page 1 of 1 (latest)

real spade
#

When testing with a friend, i noticed that if either of us hold down the fire key and the other kills the person who is holding down the fire key, the character dies and drops the weapon but the weapon continues to fire on the floor until it runs out of ammo. This happens on both server and client. I'm not quite sure where to look in the code for a fix to this.

undone pulsar
real spade
#
bool UCombatComponent::CanFire()
{
    if (EquippedWeapon == nullptr) return false;
    return !EquippedWeapon->IsEmpty() && bCanFire && CombatState == ECombatState::ECS_Unoccupied;
}
#

I'm only checking these for firing

#

however i dont think these checks would matter once the character is dead right?

#

we also disable input when the character is elimmed, so im not sure why the weapon continues to fire

undone pulsar
undone pulsar
real spade
#
void UCombatComponent::Fire()
{
    if (CanFire())
    {
        bCanFire = false;
        ServerFire(HitTarget);
        if (EquippedWeapon)
        {
            CrosshairShootFactor = 0.75f;
        }
        StartFireTimer();
    }
}
#

which is called from the character when the fire button is pressed

undone pulsar
#

show that logic too

real spade
#
void UCombatComponent::FireButtonPressed(bool bPressed)
{
    bFireButtonPressed = bPressed;

    if (bFireButtonPressed)
    {
        Fire();
    }
}
#
void ABlasterCharacter::FireButtonPressed()
{
    if (CombatComp)
    {
        CombatComp->FireButtonPressed(true);
    }
}

void ABlasterCharacter::FireButtonReleased()
{
    if (CombatComp)
    {
        CombatComp->FireButtonPressed(false);
    }
}
undone pulsar
#

found it

undone pulsar
#

you check if bFireButtonPressed is true

#

does it ever go to false again after you die?

#

because input may be turned off right?

#

so perhaps bFireButtonPressed never goes to false

#

Can you print out the value of bFireButtonPressed and go through your game again and see what it prints out and if it ever goes to false?

real spade
#

yea that's what i thought, so would i set it to false in the elimmed function?

undone pulsar
#

You could do that, but there's another check that will help before calling Fire(), not just checking if the left mouse was clicked.
You also want to make sure the replicated wepaon variable is not null

#
void UCombatComponent::FireButtonPressed(bool bPressed)
{
    
    bFireButtonPressed = bPressed;

    if(bFireButtonPressed && EquippedWeapon)
    {
        Fire();
    }
}```
#

when you die, I believe when you drop the weapon, it gets set to be null by the server

real spade
#

isn't that fine? you wont be holding a weapon if you're dead

undone pulsar
real spade
#

I see, thanks

undone pulsar
#

Also you might be at a point just before stephen adds automatic vs non automatic weapons so he might cover this later

#

So if that doesn't work, maybe keep watching and see what he says in the next video

real spade
#

is that in section with different weapon types?

#

I'm almost there, just finishing the section before that

undone pulsar