Change Slide to work with Slide Input Action

This commit is contained in:
baz 2024-01-12 15:53:23 +00:00
parent bf45b09cd7
commit 9bb3225542
2 changed files with 14 additions and 16 deletions

View File

@ -60,7 +60,7 @@ void UNakatomiCMC::FSavedMove_Nakatomi::SetMoveFor(ACharacter* C, float InDeltaT
UNakatomiCMC* CharacterMovement = Cast<UNakatomiCMC>(C->GetCharacterMovement()); UNakatomiCMC* CharacterMovement = Cast<UNakatomiCMC>(C->GetCharacterMovement());
Saved_bWantsToSprint = CharacterMovement->Safe_bWantsToSprint; Saved_bWantsToSprint = CharacterMovement->Safe_bWantsToSprint;
Saved_bPrevWantsToCrouch = CharacterMovement->Safe_bPrevWantsToCrouch; Saved_bWantsToSlide = CharacterMovement->Safe_bWantsToSlide;
} }
void UNakatomiCMC::FSavedMove_Nakatomi::PrepMoveFor(ACharacter* C) void UNakatomiCMC::FSavedMove_Nakatomi::PrepMoveFor(ACharacter* C)
@ -70,7 +70,7 @@ void UNakatomiCMC::FSavedMove_Nakatomi::PrepMoveFor(ACharacter* C)
UNakatomiCMC* CharacterMovement = Cast<UNakatomiCMC>(C->GetCharacterMovement()); UNakatomiCMC* CharacterMovement = Cast<UNakatomiCMC>(C->GetCharacterMovement());
CharacterMovement->Safe_bWantsToSprint = Saved_bWantsToSprint; CharacterMovement->Safe_bWantsToSprint = Saved_bWantsToSprint;
CharacterMovement->Safe_bPrevWantsToCrouch = Saved_bPrevWantsToCrouch; CharacterMovement->Safe_bWantsToSlide = Saved_bWantsToSlide;
} }
UNakatomiCMC::FNetworkPredictionData_Client_Nakatomi::FNetworkPredictionData_Client_Nakatomi( UNakatomiCMC::FNetworkPredictionData_Client_Nakatomi::FNetworkPredictionData_Client_Nakatomi(
@ -121,8 +121,6 @@ void UNakatomiCMC::OnMovementUpdated(float DeltaSeconds, const FVector& OldLocat
MaxWalkSpeed = Walk_MaxWalkSpeed; MaxWalkSpeed = Walk_MaxWalkSpeed;
} }
} }
Safe_bPrevWantsToCrouch = bWantsToCrouch;
} }
bool UNakatomiCMC::IsMovingOnGround() const bool UNakatomiCMC::IsMovingOnGround() const
@ -137,7 +135,7 @@ bool UNakatomiCMC::CanCrouchInCurrentState() const
void UNakatomiCMC::UpdateCharacterStateBeforeMovement(float DeltaSeconds) void UNakatomiCMC::UpdateCharacterStateBeforeMovement(float DeltaSeconds)
{ {
if (MovementMode == MOVE_Walking && !bWantsToCrouch && Safe_bPrevWantsToCrouch) if (MovementMode == MOVE_Walking && Safe_bWantsToSlide)
{ {
FHitResult PotentialSlideSurface; FHitResult PotentialSlideSurface;
if (Velocity.SizeSquared() > pow(Slide_MinSpeed, 2) && GetSlideSurface(PotentialSlideSurface)) if (Velocity.SizeSquared() > pow(Slide_MinSpeed, 2) && GetSlideSurface(PotentialSlideSurface))
@ -146,7 +144,7 @@ void UNakatomiCMC::UpdateCharacterStateBeforeMovement(float DeltaSeconds)
} }
} }
if (IsCustomMovementMode(CMOVE_Slide) && !bWantsToCrouch) if (IsCustomMovementMode(CMOVE_Slide) && !Safe_bWantsToSlide)
{ {
ExitSlide(); ExitSlide();
} }
@ -190,12 +188,12 @@ void UNakatomiCMC::DisableCrouch()
void UNakatomiCMC::EnableSlide() void UNakatomiCMC::EnableSlide()
{ {
EnterSlide(); Safe_bWantsToSlide = true;
} }
void UNakatomiCMC::DisableSlide() void UNakatomiCMC::DisableSlide()
{ {
ExitSlide(); Safe_bWantsToSlide = false;
} }
bool UNakatomiCMC::IsCustomMovementMode(ECustomMovementMove InCustomMovementMode) const bool UNakatomiCMC::IsCustomMovementMode(ECustomMovementMove InCustomMovementMode) const
@ -205,14 +203,14 @@ bool UNakatomiCMC::IsCustomMovementMode(ECustomMovementMove InCustomMovementMode
void UNakatomiCMC::EnterSlide() void UNakatomiCMC::EnterSlide()
{ {
bWantsToCrouch = true; // bWantsToCrouch = true;
Velocity += Velocity.GetSafeNormal2D() * Slide_EnterImpulse; Velocity += Velocity.GetSafeNormal2D() * Slide_EnterImpulse;
SetMovementMode(MOVE_Custom, CMOVE_Slide); SetMovementMode(MOVE_Custom, CMOVE_Slide);
} }
void UNakatomiCMC::ExitSlide() void UNakatomiCMC::ExitSlide()
{ {
bWantsToCrouch = false; // bWantsToCrouch = false;
FQuat NewRotation = FRotationMatrix::MakeFromXZ(UpdatedComponent->GetForwardVector().GetSafeNormal2D(), FVector::UpVector).ToQuat(); FQuat NewRotation = FRotationMatrix::MakeFromXZ(UpdatedComponent->GetForwardVector().GetSafeNormal2D(), FVector::UpVector).ToQuat();
FHitResult Hit; FHitResult Hit;

View File

@ -30,7 +30,7 @@ class NAKATOMI_API UNakatomiCMC : public UCharacterMovementComponent
// Flag // Flag
uint8 Saved_bWantsToSprint:1; uint8 Saved_bWantsToSprint:1;
uint8 Saved_bPrevWantsToCrouch:1; uint8 Saved_bWantsToSlide:1;
virtual bool CanCombineWith(const FSavedMovePtr& NewMove, ACharacter* InCharacter, float MaxDelta) const override; virtual bool CanCombineWith(const FSavedMovePtr& NewMove, ACharacter* InCharacter, float MaxDelta) const override;
virtual void Clear() override; virtual void Clear() override;
@ -56,19 +56,19 @@ class NAKATOMI_API UNakatomiCMC : public UCharacterMovementComponent
float Walk_MaxWalkSpeed; float Walk_MaxWalkSpeed;
UPROPERTY(EditDefaultsOnly) UPROPERTY(EditDefaultsOnly)
float Slide_MinSpeed = 10.f; float Slide_MinSpeed = 50.f;
UPROPERTY(EditDefaultsOnly) UPROPERTY(EditDefaultsOnly)
float Slide_EnterImpulse = 2000.f; float Slide_EnterImpulse = 2000.f;
UPROPERTY(EditDefaultsOnly) UPROPERTY(EditDefaultsOnly)
float Slide_GravityForce = 5000.f; float Slide_GravityForce = 2500.f;
UPROPERTY(EditDefaultsOnly) UPROPERTY(EditDefaultsOnly)
float Slide_Friction = 1.3f; float Slide_Friction = 1.f;
bool Safe_bWantsToSprint; bool Safe_bWantsToSprint;
bool Safe_bPrevWantsToCrouch; bool Safe_bWantsToSlide;
UPROPERTY(Transient) UPROPERTY(Transient)
ANakatomiCharacter* NakatomiCharacterOwner; ANakatomiCharacter* NakatomiCharacterOwner;