Finished Creating Sniper Weapon
This commit is contained in:
parent
d12573f6cc
commit
848430aebd
@ -1,3 +1,3 @@
|
|||||||
version https://git-lfs.github.com/spec/v1
|
version https://git-lfs.github.com/spec/v1
|
||||||
oid sha256:4d4a7e220c05cd641cf8f6465c767efb4bf895ca9ac7d473530dff9daeecac55
|
oid sha256:d5625ec21d5212c05429ac81906d5aa5e6ee935ee0bcbcdd16477cbd64165c16
|
||||||
size 124137
|
size 125077
|
||||||
|
BIN
EndlessVendetta/Content/FirstPerson/Blueprints/BaseWeapons/WBP_AmmoCount.uasset
(Stored with Git LFS)
BIN
EndlessVendetta/Content/FirstPerson/Blueprints/BaseWeapons/WBP_AmmoCount.uasset
(Stored with Git LFS)
Binary file not shown.
BIN
EndlessVendetta/Content/__ExternalActors__/FirstPerson/Maps/GunMechanicTester/7/VS/TBSU6BHEHN191N9FG8A6XN.uasset
(Stored with Git LFS)
Normal file
BIN
EndlessVendetta/Content/__ExternalActors__/FirstPerson/Maps/GunMechanicTester/7/VS/TBSU6BHEHN191N9FG8A6XN.uasset
(Stored with Git LFS)
Normal file
Binary file not shown.
@ -7,6 +7,7 @@
|
|||||||
#include "Components/ArrowComponent.h"
|
#include "Components/ArrowComponent.h"
|
||||||
#include "Kismet/KismetMathLibrary.h"
|
#include "Kismet/KismetMathLibrary.h"
|
||||||
#include "EndlessVendetta/InteractionInterface.h"
|
#include "EndlessVendetta/InteractionInterface.h"
|
||||||
|
#include "Engine/EngineTypes.h"
|
||||||
#include "BaseWeaponClass.generated.h"
|
#include "BaseWeaponClass.generated.h"
|
||||||
|
|
||||||
class AEndlessVendettaCharacter;
|
class AEndlessVendettaCharacter;
|
||||||
@ -55,6 +56,10 @@ public:
|
|||||||
virtual void Tick(float DeltaTime) override;
|
virtual void Tick(float DeltaTime) override;
|
||||||
void ReloadTimer();
|
void ReloadTimer();
|
||||||
|
|
||||||
|
float currentPitch;
|
||||||
|
|
||||||
|
UPROPERTY(EditAnywhere)
|
||||||
|
float BulletDistance;
|
||||||
|
|
||||||
UPROPERTY(EditAnywhere, BlueprintReadWrite)
|
UPROPERTY(EditAnywhere, BlueprintReadWrite)
|
||||||
FString WeaponName;
|
FString WeaponName;
|
||||||
@ -177,14 +182,10 @@ protected:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
UPROPERTY(EditAnywhere)
|
|
||||||
float BulletDistance;
|
|
||||||
|
|
||||||
float originalMagnitude;
|
float originalMagnitude;
|
||||||
float originalMaxAngleLeft;
|
float originalMaxAngleLeft;
|
||||||
float originalMaxAngleRight;
|
float originalMaxAngleRight;
|
||||||
float originalMinMultiplier;
|
float originalMinMultiplier;
|
||||||
|
|
||||||
float currentPitch;
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
@ -2,7 +2,10 @@
|
|||||||
|
|
||||||
|
|
||||||
#include "SniperClass.h"
|
#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
|
// Sets default values
|
||||||
ASniperClass::ASniperClass()
|
ASniperClass::ASniperClass()
|
||||||
@ -15,24 +18,77 @@ ASniperClass::ASniperClass()
|
|||||||
void ASniperClass::BeginPlay()
|
void ASniperClass::BeginPlay()
|
||||||
{
|
{
|
||||||
Super::BeginPlay();
|
Super::BeginPlay();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Called every frame
|
// Called every frame
|
||||||
void ASniperClass::Tick(float DeltaTime)
|
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()
|
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)
|
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;
|
||||||
|
}
|
||||||
|
@ -4,7 +4,6 @@
|
|||||||
|
|
||||||
#include "CoreMinimal.h"
|
#include "CoreMinimal.h"
|
||||||
#include "BaseWeaponClass.h"
|
#include "BaseWeaponClass.h"
|
||||||
#include "EndlessVendettaCharacter.h"
|
|
||||||
#include "SniperClass.generated.h"
|
#include "SniperClass.generated.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -27,10 +26,17 @@ public:
|
|||||||
// Called every frame
|
// Called every frame
|
||||||
virtual void Tick(float DeltaTime) override;
|
virtual void Tick(float DeltaTime) override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
bool bSingleShotOnly;
|
||||||
|
FTimerHandle SniperTimerHandle;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
virtual void Fire() override;
|
virtual void Fire() override;
|
||||||
|
|
||||||
virtual void ApplyRecoil(float DeltaTime) override;
|
virtual void ApplyRecoil(float DeltaTime) override;
|
||||||
|
|
||||||
|
void StopFire();
|
||||||
|
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user