Section 11: Multiple Weapon Types - Lecture 213
This commit is contained in:
parent
473271348a
commit
d2221d2334
BIN
Content/_Game/Assets/Sounds/Gunshots/AR15_Generic_Shot_Cue.uasset (Stored with Git LFS)
Normal file
BIN
Content/_Game/Assets/Sounds/Gunshots/AR15_Generic_Shot_Cue.uasset (Stored with Git LFS)
Normal file
Binary file not shown.
BIN
Content/_Game/DataTable/WeaponDataTable.uasset (Stored with Git LFS)
BIN
Content/_Game/DataTable/WeaponDataTable.uasset (Stored with Git LFS)
Binary file not shown.
|
@ -52,7 +52,6 @@ AShooterCharacter::AShooterCharacter() :
|
||||||
// Automatic fire
|
// Automatic fire
|
||||||
bFireButtonPressed(false),
|
bFireButtonPressed(false),
|
||||||
bShouldFire(true),
|
bShouldFire(true),
|
||||||
AutomaticFireRate(0.1f),
|
|
||||||
// Item trace variables
|
// Item trace variables
|
||||||
bShouldTraceForItems(false),
|
bShouldTraceForItems(false),
|
||||||
// Camera interp location variables
|
// Camera interp location variables
|
||||||
|
@ -577,9 +576,11 @@ void AShooterCharacter::FireWeapon()
|
||||||
|
|
||||||
void AShooterCharacter::StartFireTimer()
|
void AShooterCharacter::StartFireTimer()
|
||||||
{
|
{
|
||||||
|
if (!EquippedWeapon) return;
|
||||||
|
|
||||||
CombatState = ECombatState::ECS_FireTimerInProgress;
|
CombatState = ECombatState::ECS_FireTimerInProgress;
|
||||||
GetWorldTimerManager().SetTimer(AutoFireTimer, this, &AShooterCharacter::AutoFireReset,
|
GetWorldTimerManager().SetTimer(AutoFireTimer, this, &AShooterCharacter::AutoFireReset,
|
||||||
AutomaticFireRate);
|
EquippedWeapon->GetAutoFireRate());
|
||||||
}
|
}
|
||||||
|
|
||||||
void AShooterCharacter::AutoFireReset()
|
void AShooterCharacter::AutoFireReset()
|
||||||
|
@ -601,9 +602,10 @@ void AShooterCharacter::AutoFireReset()
|
||||||
void AShooterCharacter::PlayFireSound()
|
void AShooterCharacter::PlayFireSound()
|
||||||
{
|
{
|
||||||
// Play fire sound
|
// Play fire sound
|
||||||
if (FireSound)
|
if (!EquippedWeapon) return;
|
||||||
|
if (EquippedWeapon->GetFireSound())
|
||||||
{
|
{
|
||||||
UGameplayStatics::PlaySound2D(this, FireSound);
|
UGameplayStatics::PlaySound2D(this, EquippedWeapon->GetFireSound());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -615,9 +617,10 @@ void AShooterCharacter::SendBullet()
|
||||||
|
|
||||||
const FTransform SocketTransform = BarrelSocket->GetSocketTransform(EquippedWeapon->GetItemMesh());
|
const FTransform SocketTransform = BarrelSocket->GetSocketTransform(EquippedWeapon->GetItemMesh());
|
||||||
|
|
||||||
if (MuzzleFlash)
|
if (!EquippedWeapon) return;
|
||||||
|
if (EquippedWeapon->GetMuzzleFlash())
|
||||||
{
|
{
|
||||||
UGameplayStatics::SpawnEmitterAtLocation(GetWorld(), MuzzleFlash, SocketTransform);
|
UGameplayStatics::SpawnEmitterAtLocation(GetWorld(), EquippedWeapon->GetMuzzleFlash(), SocketTransform);
|
||||||
}
|
}
|
||||||
|
|
||||||
FVector BeamEnd;
|
FVector BeamEnd;
|
||||||
|
|
|
@ -267,14 +267,6 @@ private:
|
||||||
meta = (ClampMin = 0.0, ClampMax = 1.0, UIMin = 0.0, UIMax = 1.0))
|
meta = (ClampMin = 0.0, ClampMax = 1.0, UIMin = 0.0, UIMax = 1.0))
|
||||||
float MouseAimingLookUpRate;
|
float MouseAimingLookUpRate;
|
||||||
|
|
||||||
/* Randomized gunshot sound cue*/
|
|
||||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Combat, meta = (AllowPrivateAccess = true))
|
|
||||||
USoundCue* FireSound;
|
|
||||||
|
|
||||||
/* Flash spawned at BarrelSocket */
|
|
||||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Combat, meta = (AllowPrivateAccess = true))
|
|
||||||
UParticleSystem* MuzzleFlash;
|
|
||||||
|
|
||||||
/* Montage for firing the weapon */
|
/* Montage for firing the weapon */
|
||||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Combat, meta = (AllowPrivateAccess = true))
|
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Combat, meta = (AllowPrivateAccess = true))
|
||||||
UAnimMontage* HipFireMontage;
|
UAnimMontage* HipFireMontage;
|
||||||
|
@ -336,9 +328,6 @@ private:
|
||||||
/* True when we cane fire. False when waiting for the timer */
|
/* True when we cane fire. False when waiting for the timer */
|
||||||
bool bShouldFire;
|
bool bShouldFire;
|
||||||
|
|
||||||
/* Rate of automatic gun fire */
|
|
||||||
float AutomaticFireRate;
|
|
||||||
|
|
||||||
/* Sets a timer between gunshots */
|
/* Sets a timer between gunshots */
|
||||||
FTimerHandle AutoFireTimer;
|
FTimerHandle AutoFireTimer;
|
||||||
|
|
||||||
|
|
|
@ -126,6 +126,10 @@ void AWeapon::OnConstruction(const FTransform& Transform)
|
||||||
CrosshairsRight = WeaponDataRow->CrosshairsRight;
|
CrosshairsRight = WeaponDataRow->CrosshairsRight;
|
||||||
CrosshairsBottom = WeaponDataRow->CrosshairsBottom;
|
CrosshairsBottom = WeaponDataRow->CrosshairsBottom;
|
||||||
CrosshairsTop = WeaponDataRow->CrosshairsTop;
|
CrosshairsTop = WeaponDataRow->CrosshairsTop;
|
||||||
|
|
||||||
|
AutoFireRate = WeaponDataRow->AutoFireRate;
|
||||||
|
MuzzleFlash = WeaponDataRow->MuzzleFlash;
|
||||||
|
FireSound = WeaponDataRow->FireSound;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (GetMaterialInstance())
|
if (GetMaterialInstance())
|
||||||
|
|
|
@ -12,6 +12,7 @@
|
||||||
|
|
||||||
class USoundCue;
|
class USoundCue;
|
||||||
class UWidgetComponent;
|
class UWidgetComponent;
|
||||||
|
class UParticleSystem;
|
||||||
|
|
||||||
USTRUCT(BlueprintType)
|
USTRUCT(BlueprintType)
|
||||||
struct FWeaponDataTable : public FTableRowBase
|
struct FWeaponDataTable : public FTableRowBase
|
||||||
|
@ -74,6 +75,15 @@ struct FWeaponDataTable : public FTableRowBase
|
||||||
|
|
||||||
UPROPERTY(EditAnywhere, BlueprintReadWrite)
|
UPROPERTY(EditAnywhere, BlueprintReadWrite)
|
||||||
UTexture2D* CrosshairsTop;
|
UTexture2D* CrosshairsTop;
|
||||||
|
|
||||||
|
UPROPERTY(EditAnywhere, BlueprintReadWrite)
|
||||||
|
float AutoFireRate;
|
||||||
|
|
||||||
|
UPROPERTY(EditAnywhere, BlueprintReadWrite)
|
||||||
|
UParticleSystem* MuzzleFlash;
|
||||||
|
|
||||||
|
UPROPERTY(EditAnywhere, BlueprintReadWrite)
|
||||||
|
USoundCue* FireSound;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -148,6 +158,19 @@ private:
|
||||||
|
|
||||||
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = DataTable, meta = (AllowPrivateAccess = "true"))
|
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = DataTable, meta = (AllowPrivateAccess = "true"))
|
||||||
UTexture2D* CrosshairsTop;
|
UTexture2D* CrosshairsTop;
|
||||||
|
|
||||||
|
/** The speed at which automatic fire happens */
|
||||||
|
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = DataTable, meta = (AllowPrivateAccess = "true"))
|
||||||
|
float AutoFireRate;
|
||||||
|
|
||||||
|
/** Particle system spawned at the BarrelSocket */
|
||||||
|
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = DataTable, meta = (AllowPrivateAccess = "true"))
|
||||||
|
UParticleSystem* MuzzleFlash;
|
||||||
|
|
||||||
|
/** Sound played when the weapon is fired */
|
||||||
|
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = DataTable, meta = (AllowPrivateAccess = "true"))
|
||||||
|
USoundCue* FireSound;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/** Adds an impulse to the weapon */
|
/** Adds an impulse to the weapon */
|
||||||
void ThrowWeapon();
|
void ThrowWeapon();
|
||||||
|
@ -162,6 +185,9 @@ public:
|
||||||
FORCEINLINE int32 GetMagazineCapacity() const { return MagazineCapacity; }
|
FORCEINLINE int32 GetMagazineCapacity() const { return MagazineCapacity; }
|
||||||
FORCEINLINE FName GetReloadMontageSection() const { return ReloadMontageSection; }
|
FORCEINLINE FName GetReloadMontageSection() const { return ReloadMontageSection; }
|
||||||
FORCEINLINE FName GetClipBoneName() const { return ClipBoneName; }
|
FORCEINLINE FName GetClipBoneName() const { return ClipBoneName; }
|
||||||
|
FORCEINLINE float GetAutoFireRate() const { return AutoFireRate; }
|
||||||
|
FORCEINLINE UParticleSystem* GetMuzzleFlash() const { return MuzzleFlash; }
|
||||||
|
FORCEINLINE USoundCue* GetFireSound() const { return FireSound; }
|
||||||
|
|
||||||
void ReloadAmmo(int32 Amount);
|
void ReloadAmmo(int32 Amount);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue