diff --git a/Content/Assets/MilitaryWeapSilver/Weapons/Animations/Fire_Shotgun_W.uasset b/Content/Assets/MilitaryWeapSilver/Weapons/Animations/Fire_Shotgun_W.uasset index bc2c66d..8ed6843 100644 Binary files a/Content/Assets/MilitaryWeapSilver/Weapons/Animations/Fire_Shotgun_W.uasset and b/Content/Assets/MilitaryWeapSilver/Weapons/Animations/Fire_Shotgun_W.uasset differ diff --git a/Content/Assets/MilitaryWeapSilver/Weapons/Shotgun_A.uasset b/Content/Assets/MilitaryWeapSilver/Weapons/Shotgun_A.uasset index fe0e905..b7351b1 100644 Binary files a/Content/Assets/MilitaryWeapSilver/Weapons/Shotgun_A.uasset and b/Content/Assets/MilitaryWeapSilver/Weapons/Shotgun_A.uasset differ diff --git a/Content/Assets/MilitaryWeapSilver/Weapons/Shotgun_A_Skeleton.uasset b/Content/Assets/MilitaryWeapSilver/Weapons/Shotgun_A_Skeleton.uasset index 81c365b..d41cce5 100644 Binary files a/Content/Assets/MilitaryWeapSilver/Weapons/Shotgun_A_Skeleton.uasset and b/Content/Assets/MilitaryWeapSilver/Weapons/Shotgun_A_Skeleton.uasset differ diff --git a/Content/Assets/Textures/Crosshairs/Shotgun/shotgun_small_center.uasset b/Content/Assets/Textures/Crosshairs/Shotgun/shotgun_small_center.uasset new file mode 100644 index 0000000..0cf3339 Binary files /dev/null and b/Content/Assets/Textures/Crosshairs/Shotgun/shotgun_small_center.uasset differ diff --git a/Content/Assets/Textures/Crosshairs/Shotgun/shotgun_small_left.uasset b/Content/Assets/Textures/Crosshairs/Shotgun/shotgun_small_left.uasset new file mode 100644 index 0000000..7487086 Binary files /dev/null and b/Content/Assets/Textures/Crosshairs/Shotgun/shotgun_small_left.uasset differ diff --git a/Content/Assets/Textures/Crosshairs/Shotgun/shotgun_small_right.uasset b/Content/Assets/Textures/Crosshairs/Shotgun/shotgun_small_right.uasset new file mode 100644 index 0000000..af93fdf Binary files /dev/null and b/Content/Assets/Textures/Crosshairs/Shotgun/shotgun_small_right.uasset differ diff --git a/Content/Blueprints/Weapon/BP_Shotgun.uasset b/Content/Blueprints/Weapon/BP_Shotgun.uasset new file mode 100644 index 0000000..1ebcf26 Binary files /dev/null and b/Content/Blueprints/Weapon/BP_Shotgun.uasset differ diff --git a/Content/Blueprints/Weapon/Casings/BP_ShotGunCasing.uasset b/Content/Blueprints/Weapon/Casings/BP_ShotGunCasing.uasset new file mode 100644 index 0000000..471e10d Binary files /dev/null and b/Content/Blueprints/Weapon/Casings/BP_ShotGunCasing.uasset differ diff --git a/Content/Maps/BlasterMap.umap b/Content/Maps/BlasterMap.umap index a7731c2..49394ae 100644 Binary files a/Content/Maps/BlasterMap.umap and b/Content/Maps/BlasterMap.umap differ diff --git a/Source/Blaster/Character/BlasterCharacter.cpp b/Source/Blaster/Character/BlasterCharacter.cpp index 1a7ccdd..a21229f 100644 --- a/Source/Blaster/Character/BlasterCharacter.cpp +++ b/Source/Blaster/Character/BlasterCharacter.cpp @@ -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; diff --git a/Source/Blaster/Components/CombatComponent.cpp b/Source/Blaster/Components/CombatComponent.cpp index 1690af7..9161d68 100644 --- a/Source/Blaster/Components/CombatComponent.cpp +++ b/Source/Blaster/Components/CombatComponent.cpp @@ -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); } diff --git a/Source/Blaster/Components/CombatComponent.h b/Source/Blaster/Components/CombatComponent.h index 1835ad3..0bc841f 100644 --- a/Source/Blaster/Components/CombatComponent.h +++ b/Source/Blaster/Components/CombatComponent.h @@ -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) diff --git a/Source/Blaster/Weapon/HitScanWeapon.cpp b/Source/Blaster/Weapon/HitScanWeapon.cpp index 4b7e93d..fc1ba2c 100644 --- a/Source/Blaster/Weapon/HitScanWeapon.cpp +++ b/Source/Blaster/Weapon/HitScanWeapon.cpp @@ -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()); +} diff --git a/Source/Blaster/Weapon/HitScanWeapon.h b/Source/Blaster/Weapon/HitScanWeapon.h index 7d646ae..c21c2df 100644 --- a/Source/Blaster/Weapon/HitScanWeapon.h +++ b/Source/Blaster/Weapon/HitScanWeapon.h @@ -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; + +}; \ No newline at end of file diff --git a/Source/Blaster/Weapon/Shotgun.cpp b/Source/Blaster/Weapon/Shotgun.cpp new file mode 100644 index 0000000..6c96803 --- /dev/null +++ b/Source/Blaster/Weapon/Shotgun.cpp @@ -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(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); + } + } +} diff --git a/Source/Blaster/Weapon/Shotgun.h b/Source/Blaster/Weapon/Shotgun.h new file mode 100644 index 0000000..f4d8701 --- /dev/null +++ b/Source/Blaster/Weapon/Shotgun.h @@ -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; +}; diff --git a/Source/Blaster/Weapon/WeaponTypes.h b/Source/Blaster/Weapon/WeaponTypes.h index 932979a..eae6d80 100644 --- a/Source/Blaster/Weapon/WeaponTypes.h +++ b/Source/Blaster/Weapon/WeaponTypes.h @@ -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") }; \ No newline at end of file