Merge movement-component #1

Merged
baz merged 20 commits from movement-component into master 2024-01-18 18:30:17 +01:00
4 changed files with 64 additions and 10 deletions
Showing only changes of commit 283b536242 - Show all commits

View File

@ -5,6 +5,11 @@
#include <GameFramework/Character.h> #include <GameFramework/Character.h>
UNakatomiCMC::UNakatomiCMC(): Safe_bWantsToSprint(false)
{
NavAgentProps.bCanCrouch = true;
}
// Checks if we can combine the NewMove with the current move to save on data. // Checks if we can combine the NewMove with the current move to save on data.
// If all the data in a saved move is identical, if true, we cam tell the server to run the existing move instead. // If all the data in a saved move is identical, if true, we cam tell the server to run the existing move instead.
bool UNakatomiCMC::FSavedMove_Nakatomi::CanCombineWith(const FSavedMovePtr& NewMove, ACharacter* InCharacter, bool UNakatomiCMC::FSavedMove_Nakatomi::CanCombineWith(const FSavedMovePtr& NewMove, ACharacter* InCharacter,
@ -83,10 +88,6 @@ FNetworkPredictionData_Client* UNakatomiCMC::GetPredictionData_Client() const
return ClientPredictionData; return ClientPredictionData;
} }
UNakatomiCMC::UNakatomiCMC(): Safe_bWantsToSprint(false)
{
}
void UNakatomiCMC::UpdateFromCompressedFlags(uint8 Flags) void UNakatomiCMC::UpdateFromCompressedFlags(uint8 Flags)
{ {
Super::UpdateFromCompressedFlags(Flags); Super::UpdateFromCompressedFlags(Flags);
@ -120,3 +121,13 @@ void UNakatomiCMC::DisableSprint()
{ {
Safe_bWantsToSprint = false; Safe_bWantsToSprint = false;
} }
void UNakatomiCMC::EnableCrouch()
{
bWantsToCrouch = true;
}
void UNakatomiCMC::DisableCrouch()
{
bWantsToCrouch = false;
}

View File

@ -57,4 +57,10 @@ public:
UFUNCTION(BlueprintCallable) UFUNCTION(BlueprintCallable)
void DisableSprint(); void DisableSprint();
UFUNCTION(BlueprintCallable)
void EnableCrouch();
UFUNCTION(BlueprintCallable)
void DisableCrouch();
}; };

View File

@ -187,6 +187,12 @@ void APlayerCharacter::SetupPlayerInputComponent(UInputComponent* PlayerInputCom
{ {
Input->BindAction(PauseAction, ETriggerEvent::Completed, this, &APlayerCharacter::PauseCallback); Input->BindAction(PauseAction, ETriggerEvent::Completed, this, &APlayerCharacter::PauseCallback);
} }
if (CrouchAction)
{
Input->BindAction(CrouchAction, ETriggerEvent::Started, this, &APlayerCharacter::BeginCrouchCallback);
Input->BindAction(CrouchAction, ETriggerEvent::Completed, this, &APlayerCharacter::EndCrouchCallback);
}
} }
} }
@ -268,17 +274,21 @@ void APlayerCharacter::QuitCallback(const FInputActionInstance& Instance)
void APlayerCharacter::SetSprintingCallback(const FInputActionInstance& Instance) void APlayerCharacter::SetSprintingCallback(const FInputActionInstance& Instance)
{ {
if (NakatomiCMC) UNakatomiCMC* cmc = GetCharacterMovementComponent();
if (cmc)
{ {
NakatomiCMC->EnableSprint(); cmc->EnableSprint();
} }
} }
void APlayerCharacter::SetWalkingCallback(const FInputActionInstance& Instance) void APlayerCharacter::SetWalkingCallback(const FInputActionInstance& Instance)
{ {
if (NakatomiCMC) UNakatomiCMC* cmc = GetCharacterMovementComponent();
if (cmc)
{ {
NakatomiCMC->DisableSprint(); cmc->DisableSprint();
} }
} }
@ -536,6 +546,26 @@ void APlayerCharacter::PauseCallback(const FInputActionInstance& Instance)
} }
} }
void APlayerCharacter::BeginCrouchCallback(const FInputActionInstance& Instance)
{
UNakatomiCMC* cmc = GetCharacterMovementComponent();
if (cmc)
{
cmc->EnableCrouch();
}
}
void APlayerCharacter::EndCrouchCallback(const FInputActionInstance& Instance)
{
UNakatomiCMC* cmc = GetCharacterMovementComponent();
if (cmc)
{
cmc->DisableCrouch();
}
}
void APlayerCharacter::OnFire() void APlayerCharacter::OnFire()
{ {
if (!IsFiring || CurrentWeapon->GetAmmoCount() == 0) if (!IsFiring || CurrentWeapon->GetAmmoCount() == 0)

View File

@ -65,6 +65,9 @@ public:
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite) UPROPERTY(EditDefaultsOnly, BlueprintReadWrite)
UInputAction* AimDownSightsAction; UInputAction* AimDownSightsAction;
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite)
UInputAction* CrouchAction;
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite) UPROPERTY(EditDefaultsOnly, BlueprintReadWrite)
TSoftObjectPtr<UInputMappingContext> InputMappingContext; TSoftObjectPtr<UInputMappingContext> InputMappingContext;
@ -175,6 +178,10 @@ public:
void PauseCallback(const FInputActionInstance& Instance); void PauseCallback(const FInputActionInstance& Instance);
void BeginCrouchCallback(const FInputActionInstance& Instance);
void EndCrouchCallback(const FInputActionInstance& Instance);
virtual void OnFire() override; virtual void OnFire() override;
void WeaponCooldownHandler(); void WeaponCooldownHandler();