From d758272d9de6d76f038ec71f9aad8912dd903e63 Mon Sep 17 00:00:00 2001 From: baz Date: Tue, 16 Jan 2024 19:44:23 +0000 Subject: [PATCH] Reimplement Aim Down Sights movement modifiers --- Content/Player/PlayerCharacter.uasset | 4 ++-- Source/Nakatomi/NakatomiCMC.cpp | 31 ++++++++++++++++++++++++++- Source/Nakatomi/NakatomiCMC.h | 23 ++++++++++++++++---- Source/Nakatomi/PlayerCharacter.cpp | 30 +++++++++++--------------- Source/Nakatomi/PlayerCharacter.h | 6 +----- 5 files changed, 64 insertions(+), 30 deletions(-) diff --git a/Content/Player/PlayerCharacter.uasset b/Content/Player/PlayerCharacter.uasset index 5e9b6ea..e88a110 100644 --- a/Content/Player/PlayerCharacter.uasset +++ b/Content/Player/PlayerCharacter.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:587f042237e7a5d1f718068f17e6d94f9dd6133fadbd5bb3f8a4d652a1781adc -size 41366 +oid sha256:3ea462d39aa6bf65425c69ce94c153594148078273a10dd63d8d0af24a05dde7 +size 41367 diff --git a/Source/Nakatomi/NakatomiCMC.cpp b/Source/Nakatomi/NakatomiCMC.cpp index fb416b8..e724cbb 100644 --- a/Source/Nakatomi/NakatomiCMC.cpp +++ b/Source/Nakatomi/NakatomiCMC.cpp @@ -61,6 +61,7 @@ void UNakatomiCMC::FSavedMove_Nakatomi::SetMoveFor(ACharacter* C, float InDeltaT Saved_bWantsToSprint = CharacterMovement->Safe_bWantsToSprint; Saved_bWantsToSlide = CharacterMovement->Safe_bWantsToSlide; + Saved_bWantsToAds = CharacterMovement->Safe_bWantsToAds; } void UNakatomiCMC::FSavedMove_Nakatomi::PrepMoveFor(ACharacter* C) @@ -71,6 +72,7 @@ void UNakatomiCMC::FSavedMove_Nakatomi::PrepMoveFor(ACharacter* C) CharacterMovement->Safe_bWantsToSprint = Saved_bWantsToSprint; CharacterMovement->Safe_bWantsToSlide = Saved_bWantsToSlide; + CharacterMovement->Safe_bWantsToAds = Saved_bWantsToAds; } UNakatomiCMC::FNetworkPredictionData_Client_Nakatomi::FNetworkPredictionData_Client_Nakatomi( @@ -120,6 +122,23 @@ void UNakatomiCMC::OnMovementUpdated(float DeltaSeconds, const FVector& OldLocat { MaxWalkSpeed = Walk_MaxWalkSpeed; } + + if (Safe_bWantsToAds) + { + MaxWalkSpeed *= Ads_Multiplier; + } + } + + if (bWantsToCrouch) + { + if (Safe_bWantsToAds) + { + MaxWalkSpeedCrouched = Crouch_MaxWalkSpeed * Ads_Multiplier; + } + else + { + MaxWalkSpeedCrouched = Crouch_MaxWalkSpeed; + } } } @@ -135,7 +154,7 @@ bool UNakatomiCMC::CanCrouchInCurrentState() const void UNakatomiCMC::UpdateCharacterStateBeforeMovement(float DeltaSeconds) { - if (MovementMode == MOVE_Walking && Safe_bWantsToSlide) + if (MovementMode == MOVE_Walking && Safe_bWantsToSlide && !Safe_bWantsToAds) { FHitResult PotentialSlideSurface; if (Velocity.SizeSquared() > pow(Slide_MinSpeed, 2) && GetSlideSurface(PotentialSlideSurface)) @@ -196,6 +215,16 @@ void UNakatomiCMC::DisableSlide() Safe_bWantsToSlide = false; } +void UNakatomiCMC::EnableAds() +{ + Safe_bWantsToAds = true; +} + +void UNakatomiCMC::DisableAds() +{ + Safe_bWantsToAds = false; +} + bool UNakatomiCMC::IsCustomMovementMode(ECustomMovementMove InCustomMovementMode) const { return MovementMode == MOVE_Custom && CustomMovementMode == InCustomMovementMode; diff --git a/Source/Nakatomi/NakatomiCMC.h b/Source/Nakatomi/NakatomiCMC.h index 0bccab8..29628f6 100644 --- a/Source/Nakatomi/NakatomiCMC.h +++ b/Source/Nakatomi/NakatomiCMC.h @@ -31,6 +31,8 @@ class NAKATOMI_API UNakatomiCMC : public UCharacterMovementComponent uint8 Saved_bWantsToSprint:1; uint8 Saved_bWantsToSlide:1; + + uint8 Saved_bWantsToAds:1; virtual bool CanCombineWith(const FSavedMovePtr& NewMove, ACharacter* InCharacter, float MaxDelta) const override; virtual void Clear() override; @@ -50,11 +52,14 @@ class NAKATOMI_API UNakatomiCMC : public UCharacterMovementComponent }; UPROPERTY(EditDefaultsOnly) - float Sprint_MaxWalkSpeed; + float Sprint_MaxWalkSpeed = 1000.0f; UPROPERTY(EditDefaultsOnly) - float Walk_MaxWalkSpeed; - + float Walk_MaxWalkSpeed = 500.0f; + + UPROPERTY(EditDefaultsOnly) + float Crouch_MaxWalkSpeed = 250.0f; + UPROPERTY(EditDefaultsOnly) float Slide_MinSpeed = 50.f; @@ -66,10 +71,14 @@ class NAKATOMI_API UNakatomiCMC : public UCharacterMovementComponent UPROPERTY(EditDefaultsOnly) float Slide_Friction = 1.f; + + UPROPERTY(EditDefaultsOnly) + float Ads_Multiplier = 0.5f; bool Safe_bWantsToSprint; bool Safe_bWantsToSlide; - + bool Safe_bWantsToAds; + UPROPERTY(Transient) ANakatomiCharacter* NakatomiCharacterOwner; @@ -112,6 +121,12 @@ public: UFUNCTION(BlueprintCallable) void DisableSlide(); + UFUNCTION(BlueprintCallable) + void EnableAds(); + + UFUNCTION(BlueprintCallable) + void DisableAds(); + UFUNCTION() bool IsCustomMovementMode(ECustomMovementMove InCustomMovementMode) const; diff --git a/Source/Nakatomi/PlayerCharacter.cpp b/Source/Nakatomi/PlayerCharacter.cpp index a79acd6..4a0b98a 100644 --- a/Source/Nakatomi/PlayerCharacter.cpp +++ b/Source/Nakatomi/PlayerCharacter.cpp @@ -465,22 +465,6 @@ void APlayerCharacter::OnDeath() UGameplayStatics::OpenLevel(this, FName(map), false); } -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(); @@ -499,7 +483,12 @@ void APlayerCharacter::BeginAimDownSightsCallback(const FInputActionInstance& In { IsADS = true; - SetMovementSpeed(); + UNakatomiCMC* cmc = GetCharacterMovementComponent(); + + if (cmc) + { + cmc->EnableAds(); + } AimSensitivity = DefaultAimSensitivity * ADSAimSensitivityMultiplier; @@ -522,7 +511,12 @@ void APlayerCharacter::EndAimDownSightsCallback(const FInputActionInstance& Inst { IsADS = false; - SetMovementSpeed(); + UNakatomiCMC* cmc = GetCharacterMovementComponent(); + + if (cmc) + { + cmc->DisableAds(); + } AimSensitivity = DefaultAimSensitivity; diff --git a/Source/Nakatomi/PlayerCharacter.h b/Source/Nakatomi/PlayerCharacter.h index d042695..49e4e38 100644 --- a/Source/Nakatomi/PlayerCharacter.h +++ b/Source/Nakatomi/PlayerCharacter.h @@ -89,9 +89,6 @@ protected: UPROPERTY(EditDefaultsOnly, BlueprintReadWrite) float SprintSpeedMultiplier = 2.0f; - UPROPERTY(EditDefaultsOnly, BlueprintReadWrite) - float ADSSpeedMultiplier = 0.5f; - UPROPERTY(EditDefaultsOnly, BlueprintReadWrite) float ADSAimSensitivityMultiplier = 0.5f; @@ -224,6 +221,5 @@ protected: virtual void OnDamaged() override; virtual void OnDeath() override; - - void SetMovementSpeed(); + };