Download

Shotgun & Some other weapon problems

Hi guys, I have some problems, and I can’t figure it out to fix them, so I thought I might ask for some advice. I’m using the Epic Survival Game C++ Project as a base for this.
The first is a recoil system which is basically getting the Yaw/Pitch movement and the spread from curves. It’s basically and FPS/TPS, the weapon kicks up a but, goes down, kicks up again.
It’s all fine and working, but for some reason the down facing force not really applying. It’s only adding to the Yaw & Pitch or just stops adding up if the player stops shooting.
There’s the code:
SweaponInstant.cpp



if (RecoilCurve)
{
const FVector Recoil = RecoilCurve->GetVectorValue(BurstCounter);
const float Imprecision = GetCurrentSpread();

MyPawn->TargetPitchRecoil += Recoil.X;
MyPawn->TargetYawRecoil += Recoil.Y;
}


And the Tick in SCharacter.cpp



/**
* Recoil
*/
if(IsFiring())
{
// Interpolate recoil to target recoil
PitchRecoil = FMath::FInterpTo(PitchRecoil, TargetPitchRecoil * 0.5f, DeltaTime, 8.f);
YawRecoil = FMath::FInterpTo(YawRecoil, TargetYawRecoil * 0.5f, DeltaTime, 8.f);
}
// Interpolate target recoils to 0, only when not shooting
TargetPitchRecoil = FMath::FInterpConstantTo(TargetPitchRecoil, 0.f, DeltaTime, 16.f);
TargetYawRecoil = FMath::FInterpConstantTo(TargetYawRecoil, 0.f, DeltaTime, 16.f);

// Apply recoil to view rotation
AddControllerPitchInput(-TargetPitchRecoil * 0.5f * DeltaTime);
AddControllerYawInput(YawRecoil * 0.5f * DeltaTime);


And my 2nd question is about reloading a shotgun… I got it synced with the server, all the traces are visible, the spread works… But the reloading…
I can’t figure out how to loop the shell reloading in c++, and how to play the cocking animation after each shot/full reload. This is what I got in the reload code



void ASWeapon::ReloadWeapon()
{
//PlayAnimation(ReloadAnimation);

if (ReloadType == EReloadType::ERT_MagReload)
{
// Number of rounds needed to fill magazine
const uint16 RoundsNeeded = MaxAmmoPerClip - CurrentAmmoInClip;
if (MaxAmmo >= RoundsNeeded)
{
// If enough ammunition exists, fill magazine and subtract ammunition
CurrentAmmoInClip = MaxAmmoPerClip;
MaxAmmo -= RoundsNeeded;
}
else
{
// Else fill magazine and empty ammunition
CurrentAmmoInClip += MaxAmmo;
MaxAmmo = 0;
}
}
if (ReloadType == EReloadType::ERT_ShellReload)
{
// Reload single bullet
CurrentAmmoInClip += AmmoIncrement;
MaxAmmo -= AmmoIncrement;

if (CurrentAmmoInClip < MaxAmmoPerClip)
{
/*
GetWorldTimerManager().ClearTimer(TimerHandle_ReloadWeapon);
if (GetWorldTimerManager().IsTimerActive(TimerHandle_StopReload))
{
GetWorldTimerManager().ClearTimer(TimerHandle_StopReload);
}
*/
// Continue reload if magazine is not full yet
GetWorldTimerManager().SetTimer(TimerHandle_ShellInClip, this, &ASWeapon::ReloadWeapon, ReloadAnimation.Length + 0.1f, false); //StartReload();
}
else
{
ReloadWeaponChamber();
}
}
}


If anyone have any idea for any of my miserable problem, I would be really grateful. I’m really thinking about re-writing the whole thing to State machines