Reimplement Aim Down Sights movement modifiers

This commit is contained in:
baz 2024-01-16 19:44:23 +00:00
parent ed84a592ef
commit d758272d9d
5 changed files with 64 additions and 30 deletions

BIN
Content/Player/PlayerCharacter.uasset (Stored with Git LFS)

Binary file not shown.

View File

@ -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;

View File

@ -32,6 +32,8 @@ class NAKATOMI_API UNakatomiCMC : public UCharacterMovementComponent
uint8 Saved_bWantsToSlide:1;
uint8 Saved_bWantsToAds:1;
virtual bool CanCombineWith(const FSavedMovePtr& NewMove, ACharacter* InCharacter, float MaxDelta) const override;
virtual void Clear() override;
virtual uint8 GetCompressedFlags() const override;
@ -50,10 +52,13 @@ 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;
@ -67,8 +72,12 @@ 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;

View File

@ -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<float>();
@ -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;

View File

@ -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;
@ -225,5 +222,4 @@ protected:
virtual void OnDeath() override;
void SetMovementSpeed();
};