From 517e3377b2f5027cb6bcaad970d434336f236164 Mon Sep 17 00:00:00 2001 From: meishibiezb <750783119@qq.com> Date: Sun, 15 Mar 2026 01:39:06 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=A2=9E=E5=8A=A0=E8=B9=B2=E4=B8=8B?= =?UTF-8?q?=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Content/Blueprints/BP_TestChar.uasset | 4 ++-- Content/Inputs/IA/IA_CrouchAction.uasset | 3 +++ Content/Inputs/IMC/IMC_Context.uasset | 4 ++-- Source/lonese/MyCharacter.cpp | 23 ++++++++++++++++++++++- Source/lonese/MyCharacter.h | 12 ++++++++++++ 5 files changed, 41 insertions(+), 5 deletions(-) create mode 100644 Content/Inputs/IA/IA_CrouchAction.uasset diff --git a/Content/Blueprints/BP_TestChar.uasset b/Content/Blueprints/BP_TestChar.uasset index c480c02..f136777 100644 --- a/Content/Blueprints/BP_TestChar.uasset +++ b/Content/Blueprints/BP_TestChar.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:6ac38f4a38f72a3a97b438f3d68fd8eaac42b95a6402ac7457916168a33f2930 -size 36300 +oid sha256:1197407138c019ab4329fc01ffc4f3aa105ffe2cd4643d214009e654780203b6 +size 36615 diff --git a/Content/Inputs/IA/IA_CrouchAction.uasset b/Content/Inputs/IA/IA_CrouchAction.uasset new file mode 100644 index 0000000..5af22a2 --- /dev/null +++ b/Content/Inputs/IA/IA_CrouchAction.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:97bbea6820391de07fec8d7fd5728165e96c431df465e0f22ddd1676f8b4b2d5 +size 1182 diff --git a/Content/Inputs/IMC/IMC_Context.uasset b/Content/Inputs/IMC/IMC_Context.uasset index b99987c..199e054 100644 --- a/Content/Inputs/IMC/IMC_Context.uasset +++ b/Content/Inputs/IMC/IMC_Context.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:19b9a971e8f3dfd8084835586af6704e6069ced3be12b0a4dcf066c89f9fada5 -size 4873 +oid sha256:3fe69f4904326e07bad7a60dc0856c2cde5bb7a18357ed1528ab266b6c7425f0 +size 5344 diff --git a/Source/lonese/MyCharacter.cpp b/Source/lonese/MyCharacter.cpp index c2b15d2..8edecbe 100644 --- a/Source/lonese/MyCharacter.cpp +++ b/Source/lonese/MyCharacter.cpp @@ -27,19 +27,36 @@ 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 void AMyCharacter::BeginPlay() { Super::BeginPlay(); - + } // Called every frame @@ -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); + } } } diff --git a/Source/lonese/MyCharacter.h b/Source/lonese/MyCharacter.h index f0bb59c..20b0816 100644 --- a/Source/lonese/MyCharacter.h +++ b/Source/lonese/MyCharacter.h @@ -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; };