137 - Shotgun

This commit is contained in:
Kingsmedia 2022-05-20 12:10:21 +02:00
parent ea46373af5
commit c619f07b1e
17 changed files with 103 additions and 3 deletions

Binary file not shown.

Binary file not shown.

View File

@ -276,6 +276,9 @@ void ABlasterCharacter::PlayReloadMontage()
case EWeaponType::EWT_SubmachineGun:
SectionName = FName("Rifle"); // Todo: create SMG reload montage section
break;
case EWeaponType::EWT_Shotgun:
SectionName = FName("Rifle"); // Todo: create Shotgun reload montage section
break;
default:
SectionName = FName("Rifle");
break;

View File

@ -458,4 +458,5 @@ void UCombatComponent::InitializeCarriedAmmo()
CarriedAmmoMap.Emplace(EWeaponType::EWT_RocketLauncher, StartingRocketAmmo);
CarriedAmmoMap.Emplace(EWeaponType::EWT_Pistol, StartingPistolAmmo);
CarriedAmmoMap.Emplace(EWeaponType::EWT_SubmachineGun, StartingSMGAmmo);
CarriedAmmoMap.Emplace(EWeaponType::EWT_Shotgun, StartingShotgunAmmo);
}

View File

@ -9,8 +9,6 @@
#include "Components/ActorComponent.h"
#include "CombatComponent.generated.h"
#define TRACE_LENGTH 80000
UCLASS( ClassGroup=(Custom), meta=(BlueprintSpawnableComponent) )
class BLASTER_API UCombatComponent : public UActorComponent
{
@ -132,6 +130,9 @@ private:
UPROPERTY(EditAnywhere)
int32 StartingSMGAmmo = 15;
UPROPERTY(EditAnywhere)
int32 StartingShotgunAmmo = 15;
void InitializeCarriedAmmo();
UPROPERTY(ReplicatedUsing=OnRep_CombatState)

View File

@ -6,6 +6,7 @@
#include "Blaster/Character/BlasterCharacter.h"
#include "Engine/SkeletalMeshSocket.h"
#include "Kismet/GameplayStatics.h"
#include "Kismet/KismetMathLibrary.h"
#include "Particles/ParticleSystemComponent.h"
void AHitScanWeapon::Fire(const FVector& HitTarget)
@ -101,3 +102,24 @@ void AHitScanWeapon::Fire(const FVector& HitTarget)
}
}
}
FVector AHitScanWeapon::TraceEndWithScatter(const FVector& TraceStart, const FVector& HitTarget)
{
FVector ToTargetNormalized = (HitTarget - TraceStart).GetSafeNormal();
FVector SphereCenter = TraceStart + ToTargetNormalized * DistanceToSphere;
FVector RandVec = UKismetMathLibrary::RandomUnitVector() * FMath::FRandRange(0.f, SphereRadius);
FVector EndLoc = SphereCenter + RandVec;
FVector ToEndLoc = EndLoc - TraceStart;
DrawDebugSphere(GetWorld(), SphereCenter, SphereRadius, 12, FColor::Red, true);
DrawDebugSphere(GetWorld(), ToEndLoc, 4.f, 12, FColor::Blue, true);
DrawDebugLine(
GetWorld(),
TraceStart,
FVector(TraceStart + ToEndLoc * TRACE_LENGTH / ToEndLoc.Size()),
FColor::Cyan,
true
);
return FVector(TraceStart + ToEndLoc * TRACE_LENGTH / ToEndLoc.Size());
}

View File

@ -18,6 +18,10 @@ public:
virtual void Fire(const FVector& HitTarget) override;
protected:
FVector TraceEndWithScatter(const FVector& TraceStart, const FVector& HitTarget);
private:
UPROPERTY(EditAnywhere)
@ -37,4 +41,16 @@ private:
UPROPERTY(EditAnywhere)
USoundCue* HitSound;
// Trace end with scatter
UPROPERTY(EditAnywhere, Category = "Weapon Scatter")
float DistanceToSphere = 800.f;
UPROPERTY(EditAnywhere, Category = "Weapon Scatter")
float SphereRadius = 75.f;
UPROPERTY(EditAnywhere, Category = "Weapon Scatter")
bool bUseScatter = false;
};

View File

@ -0,0 +1,29 @@
// Fill out your copyright notice in the Description page of Project Settings.
#include "Shotgun.h"
#include "Blaster/Character/BlasterCharacter.h"
#include "Engine/SkeletalMeshSocket.h"
#include "Kismet/GameplayStatics.h"
void AShotgun::Fire(const FVector& HitTarget)
{
AWeapon::Fire(HitTarget);
APawn* OwnerPawn = Cast<APawn>(GetOwner());
if (OwnerPawn == nullptr) return;
AController* InstigatorController = OwnerPawn->GetController();
const USkeletalMeshSocket* MuzzleFlashSocket = GetWeaponMesh()->GetSocketByName("MuzzleFlash");
if (MuzzleFlashSocket)
{
FTransform SocketTransform = MuzzleFlashSocket->GetSocketTransform(GetWeaponMesh());
FVector Start = SocketTransform.GetLocation();
for (uint32 i = 0; i < NumberOfPellets; i++)
{
FVector End = TraceEndWithScatter(Start, HitTarget);
}
}
}

View File

@ -0,0 +1,25 @@
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "HitScanWeapon.h"
#include "Shotgun.generated.h"
/**
*
*/
UCLASS()
class BLASTER_API AShotgun : public AHitScanWeapon
{
GENERATED_BODY()
public:
virtual void Fire(const FVector& HitTarget) override;
private:
UPROPERTY(EditAnywhere, Category = "Weapon Scatter")
uint32 NumberOfPellets = 10;
};

View File

@ -1,5 +1,7 @@
#pragma once
#define TRACE_LENGTH 80000
UENUM(BlueprintType)
enum class EWeaponType: uint8
{
@ -7,6 +9,7 @@ enum class EWeaponType: uint8
EWT_RocketLauncher UMETA(DisplayName="Rocket Launcher"),
EWT_Pistol UMETA(DisplayName="Pistol"),
EWT_SubmachineGun UMETA(DisplayName="Submachine Gun"),
EWT_Shotgun UMETA(DisplayName="Shotgun"),
EWT_MAX UMETA(DisplayName="DefaultMAX")
};