Add ADS Weapon Spread Modifier

This commit is contained in:
Louis Hobbs 2023-07-27 22:22:14 +01:00
parent 938b4425eb
commit 929eca3204
3 changed files with 13 additions and 1 deletions

View File

@ -265,7 +265,7 @@ void APlayerCharacter::CalculateHits(TArray<FHitResult>* hits)
// Set up randomness // Set up randomness
const int32 RandomSeed = FMath::Rand(); const int32 RandomSeed = FMath::Rand();
FRandomStream WeaponRandomStream(RandomSeed); FRandomStream WeaponRandomStream(RandomSeed);
const float Spread = CurrentWeapon->GetWeaponProperties()->WeaponSpread; const float Spread = CurrentWeapon->GetWeaponProperties()->WeaponSpread * WeaponSpreadMultiplier;
const float Range = CurrentWeapon->GetWeaponProperties()->ProjectileRange; const float Range = CurrentWeapon->GetWeaponProperties()->ProjectileRange;
FVector CamStart = CameraComponent->GetComponentTransform().GetLocation(); FVector CamStart = CameraComponent->GetComponentTransform().GetLocation();
@ -419,6 +419,11 @@ void APlayerCharacter::BeginAimDownSightsCallback(const FInputActionInstance& In
AimSensitivity = DefaultAimSensitivity * ADSAimSensitivityMultiplier; AimSensitivity = DefaultAimSensitivity * ADSAimSensitivityMultiplier;
if (CurrentWeapon)
{
WeaponSpreadMultiplier = CurrentWeapon->GetWeaponProperties()->ADSWeaponSpreadMultiplier;
}
FLatentActionInfo LatentActionInfo; FLatentActionInfo LatentActionInfo;
LatentActionInfo.CallbackTarget = this; LatentActionInfo.CallbackTarget = this;
CameraComponent->AttachToComponent(CameraADSSpringArmComponent, FAttachmentTransformRules::KeepWorldTransform, CameraComponent->AttachToComponent(CameraADSSpringArmComponent, FAttachmentTransformRules::KeepWorldTransform,
@ -437,6 +442,8 @@ void APlayerCharacter::EndAimDownSightsCallback(const FInputActionInstance& Inst
AimSensitivity = DefaultAimSensitivity; AimSensitivity = DefaultAimSensitivity;
WeaponSpreadMultiplier = 1.0f;
FLatentActionInfo LatentActionInfo; FLatentActionInfo LatentActionInfo;
LatentActionInfo.CallbackTarget = this; LatentActionInfo.CallbackTarget = this;
CameraComponent->AttachToComponent(CameraSpringArmComponent, FAttachmentTransformRules::KeepWorldTransform, CameraComponent->AttachToComponent(CameraSpringArmComponent, FAttachmentTransformRules::KeepWorldTransform,

View File

@ -106,6 +106,8 @@ private:
float AimSensitivity; float AimSensitivity;
float WeaponSpreadMultiplier = 1.0;
public: public:
// Sets default values for this character's properties // Sets default values for this character's properties
APlayerCharacter(); APlayerCharacter();

View File

@ -38,6 +38,9 @@ struct FWeaponProperties
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Weapon Properties") UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Weapon Properties")
float WeaponSpread = 2.5f; float WeaponSpread = 2.5f;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Weapon Properties")
float ADSWeaponSpreadMultiplier = 0.5f;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Weapon Properties") UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Weapon Properties")
bool IsAutomatic = true; bool IsAutomatic = true;
}; };