From b8e1b5814f82d113234d63aefce16a41f506a114 Mon Sep 17 00:00:00 2001 From: meishibiezb <750783119@qq.com> Date: Tue, 17 Mar 2026 11:33:45 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=9B=B4=E6=96=B0=E8=A7=92=E8=89=B2?= =?UTF-8?q?=E7=A7=BB=E5=8A=A8=E6=97=B6=E6=97=8B=E8=BD=AC=E7=9A=84=E5=8A=9F?= =?UTF-8?q?=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Content/Blueprints/BP_TestChar.uasset | 4 ++-- Source/lonese/CameraPawn.cpp | 2 +- Source/lonese/MyCharacter.cpp | 18 ++++++++++++++++-- 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/Content/Blueprints/BP_TestChar.uasset b/Content/Blueprints/BP_TestChar.uasset index b7ad136..14468e4 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:dfe5cd1402fd915a4ea9ec7909b8ae450363b316810ac0492aa80d959eaecc9d -size 35747 +oid sha256:b755ef082e56584d4bda7dab2afff377e0cca07e9842c9030d55add56af91d24 +size 36046 diff --git a/Source/lonese/CameraPawn.cpp b/Source/lonese/CameraPawn.cpp index acdeaf8..6eb2e28 100644 --- a/Source/lonese/CameraPawn.cpp +++ b/Source/lonese/CameraPawn.cpp @@ -74,7 +74,7 @@ void ACameraPawn::BeginPlay() // 附加到父物体 this->AttachToActor(FollowTarget, FAttachmentTransformRules::KeepWorldTransform); - + this->GetRootComponent()->SetAbsolute(false, true, true); } // 设置自身旋转 diff --git a/Source/lonese/MyCharacter.cpp b/Source/lonese/MyCharacter.cpp index 4296992..2c27764 100644 --- a/Source/lonese/MyCharacter.cpp +++ b/Source/lonese/MyCharacter.cpp @@ -12,10 +12,19 @@ void AMyCharacter::Move(const FInputActionValue& Value) { auto f2d = Value.Get(); - auto f = GetActorForwardVector(); - auto r = GetActorRightVector(); + + // 移动 + auto f = FRotator(0, GetControlRotation().Yaw, 0).Vector(); + auto r = -f.Cross(FVector::UpVector); AddMovementInput(f * f2d.X); AddMovementInput(r * f2d.Y); + + // 转向 + if (f2d.SizeSquared() > 0.01f) + { + FRotator Rot = FRotator(0, FMath::Atan2(f2d.Y, f2d.X) * 180.0f / PI, 0); + SetActorRotation(Rot); + } } void AMyCharacter::BeginRun(const FInputActionValue& Value) @@ -84,6 +93,11 @@ AMyCharacter::AMyCharacter() PrimaryActorTick.bCanEverTick = true; GetCharacterMovement()->GetNavAgentPropertiesRef().bCanCrouch = true; + + // 禁用控制器旋转 + bUseControllerRotationPitch = false; + bUseControllerRotationYaw = false; + bUseControllerRotationRoll = false; } // Called when the game starts or when spawned