Add ADS aim sensitivity modifier

This commit is contained in:
Louis Hobbs 2023-07-26 22:43:29 +01:00
parent 3d4ef7e3c0
commit 938b4425eb
2 changed files with 16 additions and 2 deletions

View File

@ -72,6 +72,8 @@ void APlayerCharacter::BeginPlay()
DefaultMovementSpeed = GetCharacterMovement()->MaxWalkSpeed;
AimSensitivity = DefaultAimSensitivity;
if (!this->ActorHasTag(FName("Player")))
{
this->Tags.Add(FName("Player"));
@ -187,8 +189,8 @@ void APlayerCharacter::LookCallback(const FInputActionInstance& Instance)
if (vec2.Size() != 0.0f)
{
AddControllerYawInput(vec2.X * 45.0f * GetWorld()->GetDeltaSeconds());
AddControllerPitchInput((vec2.Y * (-1.0f)) * 45.0f * GetWorld()->GetDeltaSeconds());
AddControllerYawInput(vec2.X * AimSensitivity * GetWorld()->GetDeltaSeconds());
AddControllerPitchInput((vec2.Y * (-1.0f)) * AimSensitivity * GetWorld()->GetDeltaSeconds());
}
}
@ -415,6 +417,8 @@ void APlayerCharacter::BeginAimDownSightsCallback(const FInputActionInstance& In
SetMovementSpeed();
AimSensitivity = DefaultAimSensitivity * ADSAimSensitivityMultiplier;
FLatentActionInfo LatentActionInfo;
LatentActionInfo.CallbackTarget = this;
CameraComponent->AttachToComponent(CameraADSSpringArmComponent, FAttachmentTransformRules::KeepWorldTransform,
@ -431,6 +435,8 @@ void APlayerCharacter::EndAimDownSightsCallback(const FInputActionInstance& Inst
SetMovementSpeed();
AimSensitivity = DefaultAimSensitivity;
FLatentActionInfo LatentActionInfo;
LatentActionInfo.CallbackTarget = this;
CameraComponent->AttachToComponent(CameraSpringArmComponent, FAttachmentTransformRules::KeepWorldTransform,

View File

@ -68,9 +68,15 @@ protected:
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite)
float ADSSpeedMultiplier = 0.5f;
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite)
float ADSAimSensitivityMultiplier = 0.5f;
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite)
float CameraBlendTime = 0.1f;
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite)
float DefaultAimSensitivity = 45.0f;
private:
UPROPERTY(EditAnywhere, BlueprintReadWrite, Meta = (AllowPrivateAccess = "true"))
USpringArmComponent* CameraSpringArmComponent = nullptr;
@ -97,6 +103,8 @@ private:
bool IsSpriting = false;
bool IsADS = false;
float AimSensitivity;
public:
// Sets default values for this character's properties