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