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.
#Weapon firing when dead
33 messages · Page 1 of 1 (latest)
Try to find the part that allows your character to fire in the first place and look at the if checks there
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
Alright and where is CanFire() checked to actually call Fire()?
Depends on the logic that's allowing the weapon to keep firing, probs outside this check and in the method that triggers the fire or sets the replicated weapon variable
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
show that logic too
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);
}
}
found it
Alright so the issue is in your FireButtonpressed
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?
yea that's what i thought, so would i set it to false in the elimmed function?
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
isn't that fine? you wont be holding a weapon if you're dead
You're checking it's valid before firing. When you die, it won't be valid (it'll be set to null), therefore the weapon won't just keep firing over and over
I see, thanks
you're welcome! let me know if that works ^^
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
is that in section with different weapon types?
I'm almost there, just finishing the section before that
most likely yeah as you make pistols, rifles etc. and some are automatic some aren't