From d86b3f53a967f026fbae4d9c2fa8edf368bb4251 Mon Sep 17 00:00:00 2001 From: meishibiezb <750783119@qq.com> Date: Sun, 15 Mar 2026 18:42:17 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=A2=9E=E5=8A=A0=E6=91=84=E5=83=8F?= =?UTF-8?q?=E6=9C=BA=E8=B7=9F=E9=9A=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Content/Blueprints/BP_CameraPawn.uasset | 4 ++-- Source/lonese/CameraPawn.cpp | 21 ++++++++++++++++++--- Source/lonese/MyCharacter.cpp | 1 + 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/Content/Blueprints/BP_CameraPawn.uasset b/Content/Blueprints/BP_CameraPawn.uasset index 4a01661..1fe8e4d 100644 --- a/Content/Blueprints/BP_CameraPawn.uasset +++ b/Content/Blueprints/BP_CameraPawn.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:8007fb767b9832c2c06cb7d1048bd18090056da875e10ca63285a8f99da60289 -size 22559 +oid sha256:4b30853d4d68cccc3225e55bc819365d877635a5b70ea7f5687259de04cc4e39 +size 23756 diff --git a/Source/lonese/CameraPawn.cpp b/Source/lonese/CameraPawn.cpp index 4bf0916..05f9680 100644 --- a/Source/lonese/CameraPawn.cpp +++ b/Source/lonese/CameraPawn.cpp @@ -5,6 +5,7 @@ #include "GameFramework/SpringArmComponent.h" #include "Camera/CameraComponent.h" +#include "InputActionValue.h" void ACameraPawn::CameraZoom(const FInputActionValue& Value) { @@ -16,6 +17,10 @@ void ACameraPawn::CameraRotate(const FInputActionValue& Value) void ACameraPawn::CameraMove(const FInputActionValue& Value) { + auto f2d = Value.Get(); + auto f = GetActorForwardVector(); + auto r = GetActorRightVector(); + SetActorLocation(GetActorLocation() + f * f2d.X * 10.0f + r * f2d.Y * 10.0f); } // Sets default values @@ -31,6 +36,9 @@ ACameraPawn::ACameraPawn() SpringArmComponent->bUsePawnControlRotation = true; CameraComponent = CreateDefaultSubobject(TEXT("CameraComponent")); CameraComponent->SetupAttachment(SpringArmComponent, USpringArmComponent::SocketName); + + // 设置弹簧臂碰撞属性 + SpringArmComponent->bDoCollisionTest = false; } // Called when the game starts or when spawned @@ -38,10 +46,17 @@ void ACameraPawn::BeginPlay() { Super::BeginPlay(); - // 设置摄像头可见性 - if (CameraComponent) + if (FollowTarget) { - CameraComponent->SetVisibility(true); + // 切换到当前摄像头 + auto c = Cast(FollowTarget->GetController()); + if (c) + { + c->SetViewTarget(this); + } + + // 附加到父物体 + this->AttachToActor(FollowTarget, FAttachmentTransformRules::KeepWorldTransform); } } diff --git a/Source/lonese/MyCharacter.cpp b/Source/lonese/MyCharacter.cpp index 24941ec..4557a21 100644 --- a/Source/lonese/MyCharacter.cpp +++ b/Source/lonese/MyCharacter.cpp @@ -67,6 +67,7 @@ void AMyCharacter::BeginPlay() { FTransform SpawnTransform(GetActorRotation(), GetActorLocation()); temp = w->SpawnActorDeferred(CameraActorClass, SpawnTransform); + temp->SetActorRotation(FRotator(-60.0f, 0.0f, 0.0f)); temp->FollowTarget = this; temp->FinishSpawning(SpawnTransform); }