Finished Creating Sniper Weapon

This commit is contained in:
MH261677 2023-10-26 15:49:11 +01:00
parent d12573f6cc
commit 848430aebd
6 changed files with 82 additions and 16 deletions

View File

@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:4d4a7e220c05cd641cf8f6465c767efb4bf895ca9ac7d473530dff9daeecac55
size 124137
oid sha256:d5625ec21d5212c05429ac81906d5aa5e6ee935ee0bcbcdd16477cbd64165c16
size 125077

View File

@ -7,6 +7,7 @@
#include "Components/ArrowComponent.h"
#include "Kismet/KismetMathLibrary.h"
#include "EndlessVendetta/InteractionInterface.h"
#include "Engine/EngineTypes.h"
#include "BaseWeaponClass.generated.h"
class AEndlessVendettaCharacter;
@ -54,7 +55,11 @@ public:
// Called every frame
virtual void Tick(float DeltaTime) override;
void ReloadTimer();
float currentPitch;
UPROPERTY(EditAnywhere)
float BulletDistance;
UPROPERTY(EditAnywhere, BlueprintReadWrite)
FString WeaponName;
@ -177,14 +182,10 @@ protected:
private:
UPROPERTY(EditAnywhere)
float BulletDistance;
float originalMagnitude;
float originalMaxAngleLeft;
float originalMaxAngleRight;
float originalMinMultiplier;
float currentPitch;
};

View File

@ -2,7 +2,10 @@
#include "SniperClass.h"
#include "EndlessVendettaCharacter.h"
#include "EndlessVendetta/EndlessVendettaCharacter.h"
#include "EndlessVendetta/AI/AICharacter.h"
#include "Engine/DamageEvents.h"
#include "Kismet/GameplayStatics.h"
// Sets default values
ASniperClass::ASniperClass()
@ -15,24 +18,77 @@ ASniperClass::ASniperClass()
void ASniperClass::BeginPlay()
{
Super::BeginPlay();
}
// Called every frame
void ASniperClass::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
ApplyRecoil(DeltaTime);
recoilMagnitude = 1;
if(endlessVendettaChar->bIsPlayerMoving == false )
{
recoilResultPitch = 0;
recoilMagnitude = -1;
}
if (currentPitch < 0 && bStopShooting)
{
float increment = currentPitch * DeltaTime * 8;
currentPitch -= increment;
playerInWorld->AddControllerPitchInput(-increment);
}
}
void ASniperClass::Fire()
{
if(currentAmmoCount > 0 && !bSingleShotOnly)
{
bSingleShotOnly = true;
//do damage fallof based off distance
traceStart = GunStartArrow->GetComponentLocation();
traceEnd = traceStart + (GunStartArrow->GetForwardVector() * BulletDistance);
if (GetWorldTimerManager().IsTimerActive(timerHandle)) return;
GetWorld()->LineTraceSingleByChannel(outHit, traceStart, traceEnd, ECC_Visibility, collisionParams);
DrawDebugLine(this->GetWorld(), traceStart, traceEnd, FColor::Black , false, 0.2f, 0U, 0.2f);
playerControllerRef->PlayerCameraManager->StartCameraShake(CameraShakeClass, 1);
currentAmmoCount -= 1;
bulletCountShoot += 1;
bStopShooting = false;
GenerateRecoilVector();
ApplyRecoil(UGameplayStatics::GetWorldDeltaSeconds(this->GetWorld()));
this->GetWorld()->GetTimerManager().SetTimer(SniperTimerHandle, this, &ASniperClass::StopFire, FireRate, false);
if (outHit.bBlockingHit)
{
UE_LOG(LogTemp, Display, TEXT("Hit: %s"), *outHit.GetActor()->GetName());
if (!Cast<AAICharacter>(outHit.GetActor())) return;
Cast<AAICharacter>(outHit.GetActor())->TakeDamage(WeaponDamage, FPointDamageEvent(), GetWorld()->GetFirstPlayerController(), this);
}
}
else if(currentAmmoCount <= 0)
{
UE_LOG(LogTemp, Display, TEXT("No ammo, Ammo count: %d"), currentAmmoCount);
}
}
void ASniperClass::ApplyRecoil(float DeltaTime)
{
if (endlessVendettaChar->bIsPlayerMoving)
if (recoilTime < 0.3)
{
UE_LOG(LogTemp, Display, TEXT("playerMovingIsTrue"));
float amplitude = RecoilCurve->GetFloatValue(recoilTime); //get current value of curve in time
recoilTime += DeltaTime;
playerInWorld->AddControllerPitchInput(GetRecoilPitch(amplitude, recoilTime));
currentPitch += GetRecoilPitch(amplitude,recoilTime);
playerInWorld->AddControllerPitchInput(FMath::RandRange(-5 * DeltaTime, 5* DeltaTime));
GunStartArrow->AddRelativeRotation(FRotator(-GetRecoilPitch(amplitude, recoilTime), 0, 0));
playerInWorld->AddControllerYawInput(GetRecoilYaw(amplitude, recoilTime));
UpdateSamples(amplitude, recoilTime);
}
}
void ASniperClass::StopFire()
{
bSingleShotOnly = false;
}

View File

@ -4,7 +4,6 @@
#include "CoreMinimal.h"
#include "BaseWeaponClass.h"
#include "EndlessVendettaCharacter.h"
#include "SniperClass.generated.h"
/**
@ -27,10 +26,17 @@ public:
// Called every frame
virtual void Tick(float DeltaTime) override;
private:
bool bSingleShotOnly;
FTimerHandle SniperTimerHandle;
protected:
virtual void Fire() override;
virtual void ApplyRecoil(float DeltaTime) override;
void StopFire();
};