diff --git a/Source/Nakatomi/PlayerCharacter.cpp b/Source/Nakatomi/PlayerCharacter.cpp index a589bb8..28ba681 100644 --- a/Source/Nakatomi/PlayerCharacter.cpp +++ b/Source/Nakatomi/PlayerCharacter.cpp @@ -242,12 +242,16 @@ void APlayerCharacter::QuitCallback(const FInputActionInstance& Instance) void APlayerCharacter::SetSprintingCallback(const FInputActionInstance& Instance) { - GetCharacterMovement()->MaxWalkSpeed = DefaultMovementSpeed * SprintSpeedMultiplier; + IsSpriting = true; + + SetMovementSpeed(); } void APlayerCharacter::SetWalkingCallback(const FInputActionInstance& Instance) { - GetCharacterMovement()->MaxWalkSpeed = DefaultMovementSpeed; + IsSpriting = false; + + SetMovementSpeed(); } void APlayerCharacter::CalculateHits(TArray* hits) @@ -375,6 +379,22 @@ void APlayerCharacter::OnDeath() ClearAllTimers(); } +void APlayerCharacter::SetMovementSpeed() +{ + if (IsADS) + { + GetCharacterMovement()->MaxWalkSpeed = DefaultMovementSpeed * ADSSpeedMultiplier; + } + else if (IsSpriting) + { + GetCharacterMovement()->MaxWalkSpeed = DefaultMovementSpeed * SprintSpeedMultiplier; + } + else + { + GetCharacterMovement()->MaxWalkSpeed = DefaultMovementSpeed; + } +} + void APlayerCharacter::WeaponSwitchingCallback(const FInputActionInstance& Instance) { float value = Instance.GetValue().Get(); @@ -391,6 +411,10 @@ void APlayerCharacter::WeaponSwitchingCallback(const FInputActionInstance& Insta void APlayerCharacter::BeginAimDownSightsCallback(const FInputActionInstance& Instance) { + IsADS = true; + + SetMovementSpeed(); + FLatentActionInfo LatentActionInfo; LatentActionInfo.CallbackTarget = this; CameraComponent->AttachToComponent(CameraADSSpringArmComponent, FAttachmentTransformRules::KeepWorldTransform, @@ -403,6 +427,10 @@ void APlayerCharacter::BeginAimDownSightsCallback(const FInputActionInstance& In void APlayerCharacter::EndAimDownSightsCallback(const FInputActionInstance& Instance) { + IsADS = false; + + SetMovementSpeed(); + FLatentActionInfo LatentActionInfo; LatentActionInfo.CallbackTarget = this; CameraComponent->AttachToComponent(CameraSpringArmComponent, FAttachmentTransformRules::KeepWorldTransform, diff --git a/Source/Nakatomi/PlayerCharacter.h b/Source/Nakatomi/PlayerCharacter.h index 95421b9..d579454 100644 --- a/Source/Nakatomi/PlayerCharacter.h +++ b/Source/Nakatomi/PlayerCharacter.h @@ -65,6 +65,9 @@ protected: UPROPERTY(EditDefaultsOnly, BlueprintReadWrite) float SprintSpeedMultiplier = 2.0f; + UPROPERTY(EditDefaultsOnly, BlueprintReadWrite) + float ADSSpeedMultiplier = 0.5f; + UPROPERTY(EditDefaultsOnly, BlueprintReadWrite) float CameraBlendTime = 0.1f; @@ -91,6 +94,10 @@ private: UPROPERTY(EditAnywhere, BlueprintReadWrite, Meta = (AllowPrivateAccess = "true")) UAIPerceptionStimuliSourceComponent* PerceptionSource; + bool IsSpriting = false; + + bool IsADS = false; + public: // Sets default values for this character's properties APlayerCharacter(); @@ -159,4 +166,6 @@ protected: virtual void OnDamaged() override; virtual void OnDeath() override; + + void SetMovementSpeed(); };