diff --git a/Content/Blueprints/Anim/ABP_TestChar.uasset b/Content/Blueprints/Anim/ABP_TestChar.uasset new file mode 100644 index 0000000..eb7e108 --- /dev/null +++ b/Content/Blueprints/Anim/ABP_TestChar.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:6b4b2bab6d1a6f2a33c704dab74031555c6df1e07d058ef3f0e2a0dfbd99da70 +size 102091 diff --git a/Content/Blueprints/Anim/BS_Walk_Run.uasset b/Content/Blueprints/Anim/BS_Walk_Run.uasset new file mode 100644 index 0000000..f06a859 --- /dev/null +++ b/Content/Blueprints/Anim/BS_Walk_Run.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:5c9eed871df22234939af46e6e1512f1971bd97fea1dc9ed8f07cd51fd670216 +size 9226 diff --git a/Content/Blueprints/BP_TestChar.uasset b/Content/Blueprints/BP_TestChar.uasset index 81a91fb..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:06d7c7e081e57763f56373431a406553c46083c7b778f58fb71f6fbd9dc86ce6 -size 36123 +oid sha256:b755ef082e56584d4bda7dab2afff377e0cca07e9842c9030d55add56af91d24 +size 36046 diff --git a/Source/lonese/CameraPawn.cpp b/Source/lonese/CameraPawn.cpp index acdeaf8..80575c7 100644 --- a/Source/lonese/CameraPawn.cpp +++ b/Source/lonese/CameraPawn.cpp @@ -17,8 +17,15 @@ void ACameraPawn::CameraZoom(const FInputActionValue& Value) void ACameraPawn::CameraRotate(const FInputActionValue& Value) { auto f = Value.Get(); - FRotator r = FRotator(0.0f, f * RotateSpeed, 0.0f); + FRotator r = FRotator(0.0f, -f * RotateSpeed, 0.0f); AddActorWorldRotation(r); + + // 同时旋转控制器 + auto c = Cast(FollowTarget->GetController()); + if (c) + { + c->SetControlRotation(GetActorRotation()); + } } void ACameraPawn::CameraMove(const FInputActionValue& Value) @@ -38,6 +45,13 @@ void ACameraPawn::CameraReset(const FInputActionValue& Value) SpringArmComponent->TargetArmLength = InitialArmLength; SetActorRotation(InitialRotation); SetActorRelativeLocation(FVector::ZeroVector); + + // 同时旋转控制器 + auto c = Cast(FollowTarget->GetController()); + if (c) + { + c->SetControlRotation(GetActorRotation()); + } } // Sets default values @@ -74,7 +88,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..e12900d 100644 --- a/Source/lonese/MyCharacter.cpp +++ b/Source/lonese/MyCharacter.cpp @@ -12,10 +12,21 @@ 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 = FVector(f2d.X, f2d.Y, 0).Rotation() + FRotator(0, GetControlRotation().Yaw, 0); + float InterpSpeed = 10.0f; + FRotator NewRotation = FMath::RInterpTo(GetActorRotation(), Rot, GetWorld()->GetDeltaSeconds(), InterpSpeed); + SetActorRotation(NewRotation); + } } void AMyCharacter::BeginRun(const FInputActionValue& Value) @@ -84,6 +95,11 @@ AMyCharacter::AMyCharacter() PrimaryActorTick.bCanEverTick = true; GetCharacterMovement()->GetNavAgentPropertiesRef().bCanCrouch = true; + + // 禁用控制器旋转 + bUseControllerRotationPitch = false; + bUseControllerRotationYaw = false; + bUseControllerRotationRoll = false; } // Called when the game starts or when spawned