feat: 增加蹲下功能
This commit is contained in:
Binary file not shown.
BIN
Content/Inputs/IA/IA_CrouchAction.uasset
LFS
Normal file
BIN
Content/Inputs/IA/IA_CrouchAction.uasset
LFS
Normal file
Binary file not shown.
Binary file not shown.
@@ -27,12 +27,29 @@ void AMyCharacter::StopRun(const FInputActionValue& Value)
|
||||
GetCharacterMovement()->MaxWalkSpeed = 600.0f;
|
||||
}
|
||||
|
||||
void AMyCharacter::BeginCrouch(const FInputActionValue& Value)
|
||||
{
|
||||
bIsCrouching = true;
|
||||
GetCharacterMovement()->bWantsToCrouch = true;
|
||||
GetCharacterMovement()->Crouch();
|
||||
UE_LOG(LogTemp, Warning, TEXT("Crouching"));
|
||||
}
|
||||
|
||||
void AMyCharacter::StopCrouch(const FInputActionValue& Value)
|
||||
{
|
||||
bIsCrouching = false;
|
||||
GetCharacterMovement()->bWantsToCrouch = false;
|
||||
GetCharacterMovement()->UnCrouch();
|
||||
UE_LOG(LogTemp, Warning, TEXT("Stop Crouch"));
|
||||
}
|
||||
|
||||
// Sets default values
|
||||
AMyCharacter::AMyCharacter()
|
||||
{
|
||||
// Set this character to call Tick() every frame. You can turn this off to improve performance if you don't need it.
|
||||
PrimaryActorTick.bCanEverTick = true;
|
||||
|
||||
GetCharacterMovement()->GetNavAgentPropertiesRef().bCanCrouch = true;
|
||||
}
|
||||
|
||||
// Called when the game starts or when spawned
|
||||
@@ -75,6 +92,10 @@ void AMyCharacter::SetupPlayerInputComponent(UInputComponent* PlayerInputCompone
|
||||
EnhancedInputComponent->BindAction(RunAction, ETriggerEvent::Started, this, &AMyCharacter::BeginRun);
|
||||
EnhancedInputComponent->BindAction(RunAction, ETriggerEvent::Completed, this, &AMyCharacter::StopRun);
|
||||
}
|
||||
if (CrouchAction) {
|
||||
EnhancedInputComponent->BindAction(CrouchAction, ETriggerEvent::Started, this, &AMyCharacter::BeginCrouch);
|
||||
EnhancedInputComponent->BindAction(CrouchAction, ETriggerEvent::Completed, this, &AMyCharacter::StopCrouch);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -18,6 +18,8 @@ public:
|
||||
class UInputAction* MoveAction;
|
||||
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Input")
|
||||
class UInputAction* RunAction;
|
||||
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Input")
|
||||
class UInputAction* CrouchAction;
|
||||
|
||||
UFUNCTION(BlueprintCallable, Category = "Move")
|
||||
void Move(const FInputActionValue& Value);
|
||||
@@ -25,6 +27,15 @@ public:
|
||||
void BeginRun(const FInputActionValue& Value);
|
||||
UFUNCTION(BlueprintCallable, Category = "Move")
|
||||
void StopRun(const FInputActionValue& Value);
|
||||
UFUNCTION(BlueprintCallable, Category = "Move")
|
||||
void BeginCrouch(const FInputActionValue& Value);
|
||||
UFUNCTION(BlueprintCallable, Category = "Move")
|
||||
void StopCrouch(const FInputActionValue& Value);
|
||||
|
||||
UFUNCTION(BlueprintCallable, Category = "State")
|
||||
bool IsRunning() const { return bIsRunning; }
|
||||
UFUNCTION(BlueprintCallable, Category = "State")
|
||||
bool IsCrouching() const { return bIsCrouching; }
|
||||
|
||||
// Sets default values for this character's properties
|
||||
AMyCharacter();
|
||||
@@ -40,4 +51,5 @@ protected:
|
||||
|
||||
private:
|
||||
bool bIsRunning = false;
|
||||
bool bIsCrouching = false;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user