From 877beaa3f579bfa1715dd830c4f3d26f68fd87ed Mon Sep 17 00:00:00 2001 From: meishibiezb <750783119@qq.com> Date: Sun, 15 Mar 2026 19:06:35 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=91=84=E5=83=8F=E5=A4=B4=E7=A7=BB?= =?UTF-8?q?=E5=8A=A8?= 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_CameraMoveAction.uasset | 3 ++ Content/Inputs/IMC/IMC_Context.uasset | 4 +- Source/lonese/CameraPawn.cpp | 3 +- Source/lonese/MyCharacter.cpp | 45 ++++++++++++++++---- Source/lonese/MyCharacter.h | 6 +++ 6 files changed, 51 insertions(+), 14 deletions(-) create mode 100644 Content/Inputs/IA/IA_CameraMoveAction.uasset diff --git a/Content/Blueprints/BP_TestChar.uasset b/Content/Blueprints/BP_TestChar.uasset index 896d1f9..fc63324 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:cf0ae167d96eafdb6585a27e502eadeac22982f55d61237edead927034100a23 -size 35290 +oid sha256:cea9bb3fb1f0e6a30adffd728de10b85ea0ae09814875789ff6abb040b89b375 +size 35496 diff --git a/Content/Inputs/IA/IA_CameraMoveAction.uasset b/Content/Inputs/IA/IA_CameraMoveAction.uasset new file mode 100644 index 0000000..415493a --- /dev/null +++ b/Content/Inputs/IA/IA_CameraMoveAction.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:02ce8e2fa3c24d01036ad54822ec552533faa284e1224977229f3695def4be69 +size 1398 diff --git a/Content/Inputs/IMC/IMC_Context.uasset b/Content/Inputs/IMC/IMC_Context.uasset index 199e054..92f3995 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:3fe69f4904326e07bad7a60dc0856c2cde5bb7a18357ed1528ab266b6c7425f0 -size 5344 +oid sha256:946d7ea8f92fdf22168307e8c38808843233292d2b871c469d086075a04432e5 +size 7711 diff --git a/Source/lonese/CameraPawn.cpp b/Source/lonese/CameraPawn.cpp index 05f9680..0609fdb 100644 --- a/Source/lonese/CameraPawn.cpp +++ b/Source/lonese/CameraPawn.cpp @@ -18,8 +18,9 @@ void ACameraPawn::CameraRotate(const FInputActionValue& Value) void ACameraPawn::CameraMove(const FInputActionValue& Value) { auto f2d = Value.Get(); - auto f = GetActorForwardVector(); auto r = GetActorRightVector(); + auto f = r.Cross(FVector::UpVector); + f.Normalize(); SetActorLocation(GetActorLocation() + f * f2d.X * 10.0f + r * f2d.Y * 10.0f); } diff --git a/Source/lonese/MyCharacter.cpp b/Source/lonese/MyCharacter.cpp index 4557a21..f6c31a5 100644 --- a/Source/lonese/MyCharacter.cpp +++ b/Source/lonese/MyCharacter.cpp @@ -45,6 +45,30 @@ void AMyCharacter::StopCrouch(const FInputActionValue& Value) UE_LOG(LogTemp, Warning, TEXT("Stop Crouch")); } +void AMyCharacter::CameraMove(const FInputActionValue& Value) +{ + if (CameraActor) + { + CameraActor->CameraMove(Value); + } +} + +void AMyCharacter::CameraRotate(const FInputActionValue& Value) +{ + if (CameraActor) + { + CameraActor->CameraRotate(Value); + } +} + +void AMyCharacter::CameraZoom(const FInputActionValue& Value) +{ + if (CameraActor) + { + CameraActor->CameraZoom(Value); + } +} + // Sets default values AMyCharacter::AMyCharacter() { @@ -63,21 +87,20 @@ void AMyCharacter::BeginPlay() ACameraPawn* temp = nullptr; if (w) { + UClass* CameraClass; if (CameraActorClass) { - FTransform SpawnTransform(GetActorRotation(), GetActorLocation()); - temp = w->SpawnActorDeferred(CameraActorClass, SpawnTransform); - temp->SetActorRotation(FRotator(-60.0f, 0.0f, 0.0f)); - temp->FollowTarget = this; - temp->FinishSpawning(SpawnTransform); + CameraClass = CameraActorClass; } else { - FTransform SpawnTransform(GetActorRotation(), GetActorLocation()); - temp = w->SpawnActorDeferred(ACameraPawn::StaticClass(), SpawnTransform); - temp->FollowTarget = this; - temp->FinishSpawning(SpawnTransform); + CameraClass = ACameraPawn::StaticClass(); } + FTransform SpawnTransform(GetActorRotation(), GetActorLocation()); + temp = w->SpawnActorDeferred(CameraClass, SpawnTransform); + temp->SetActorRotation(FRotator(-60.0f, 0.0f, 0.0f)); + temp->FollowTarget = this; + temp->FinishSpawning(SpawnTransform); } if (temp) { @@ -122,6 +145,10 @@ void AMyCharacter::SetupPlayerInputComponent(UInputComponent* PlayerInputCompone EnhancedInputComponent->BindAction(CrouchAction, ETriggerEvent::Started, this, &AMyCharacter::BeginCrouch); EnhancedInputComponent->BindAction(CrouchAction, ETriggerEvent::Completed, this, &AMyCharacter::StopCrouch); } + if (CameraMoveAction) + { + EnhancedInputComponent->BindAction(CameraMoveAction, ETriggerEvent::Triggered, this, &AMyCharacter::CameraMove); + } } } diff --git a/Source/lonese/MyCharacter.h b/Source/lonese/MyCharacter.h index 15cbbfd..fc2cb3d 100644 --- a/Source/lonese/MyCharacter.h +++ b/Source/lonese/MyCharacter.h @@ -20,6 +20,8 @@ public: class UInputAction* RunAction; UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Input") class UInputAction* CrouchAction; + UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Input") + class UInputAction* CameraMoveAction; UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Camera") class TSubclassOf CameraActorClass; @@ -58,4 +60,8 @@ private: UPROPERTY(VisibleInstanceOnly, Category = "Camera") class ACameraPawn* CameraActor; + + void CameraZoom(const FInputActionValue& Value); + void CameraRotate(const FInputActionValue& Value); + void CameraMove(const FInputActionValue& Value); };