diff --git a/ProjectFish/Binaries/Win64/UnrealEditor-ProjectFish.pdb b/ProjectFish/Binaries/Win64/UnrealEditor-ProjectFish.pdb index 295252f..f387222 100644 Binary files a/ProjectFish/Binaries/Win64/UnrealEditor-ProjectFish.pdb and b/ProjectFish/Binaries/Win64/UnrealEditor-ProjectFish.pdb differ diff --git a/ProjectFish/Content/Gameplay/Ship/BP_Ship.uasset b/ProjectFish/Content/Gameplay/Ship/BP_Ship.uasset index b4cafb3..59ac998 100644 Binary files a/ProjectFish/Content/Gameplay/Ship/BP_Ship.uasset and b/ProjectFish/Content/Gameplay/Ship/BP_Ship.uasset differ diff --git a/ProjectFish/Source/ProjectFish/Gameplay/Ship/Shipbase.cpp b/ProjectFish/Source/ProjectFish/Gameplay/Ship/Shipbase.cpp index a6c95bb..764df67 100644 --- a/ProjectFish/Source/ProjectFish/Gameplay/Ship/Shipbase.cpp +++ b/ProjectFish/Source/ProjectFish/Gameplay/Ship/Shipbase.cpp @@ -27,7 +27,11 @@ AShipbase::AShipbase() bUseControllerRotationRoll = false; //默认movement - GetCharacterMovement()->bOrientRotationToMovement = true; // Character moves in the direction of input... + //GetCharacterMovement()->bOrientRotationToMovement = true; // Character moves in the direction of input... + //修改移动模式 + GetCharacterMovement()->bOrientRotationToMovement = false; // Don't auto-orient to movement direction + GetCharacterMovement()->bUseControllerDesiredRotation = true; // Use controller rotation for turning + GetCharacterMovement()->bUseSeparateBrakingFriction = true; GetCharacterMovement()->RotationRate = FRotator(0.0f, 500.0f, 0.0f); // ...at this rotation rate GetCharacterMovement()->MaxWalkSpeed = 500.f; @@ -46,7 +50,7 @@ AShipbase::AShipbase() CameraBoom->SetupAttachment(RootComponent); CameraBoom->TargetArmLength = 400.0f; // The camera follows at this distance behind the character CameraBoom->bUsePawnControlRotation = true; // Rotate the arm based on the controller - + CameraBoom->bDoCollisionTest = false; //关闭碰撞遮挡检测 //camera FollowCamera = CreateDefaultSubobject(TEXT("FollowCamera")); FollowCamera->SetupAttachment(CameraBoom, USpringArmComponent::SocketName); // Attach the camera to the end of the boom and let the boom adjust to match the controller orientation @@ -134,21 +138,64 @@ void AShipbase::Move(const FInputActionValue& Value) // input is a Vector2D FVector2D MovementVector = Value.Get(); + // if (Controller != nullptr) + // { + // // find out which way is forward + // const FRotator Rotation = Controller->GetControlRotation(); + // const FRotator YawRotation(0, Rotation.Yaw, 0); + // + // // get forward vector + // const FVector ForwardDirection = FRotationMatrix(YawRotation).GetUnitAxis(EAxis::X); + // + // // get right vector + // const FVector RightDirection = FRotationMatrix(YawRotation).GetUnitAxis(EAxis::Y); + // + // // add movement + // AddMovementInput(ForwardDirection, MovementVector.Y); + // AddMovementInput(RightDirection, MovementVector.X); + // } + //修改移动转向逻辑 if (Controller != nullptr) { - // find out which way is forward - const FRotator Rotation = Controller->GetControlRotation(); - const FRotator YawRotation(0, Rotation.Yaw, 0); - - // get forward vector - const FVector ForwardDirection = FRotationMatrix(YawRotation).GetUnitAxis(EAxis::X); - - // get right vector - const FVector RightDirection = FRotationMatrix(YawRotation).GetUnitAxis(EAxis::Y); - - // add movement - AddMovementInput(ForwardDirection, MovementVector.Y); - AddMovementInput(RightDirection, MovementVector.X); + // Store input values + float ForwardInput = MovementVector.Y; // W/S keys for forward/backward + float TurnInput = MovementVector.X; // A/D keys for turning + + // Only move forward/backward along character's current facing direction + if (FMath::Abs(ForwardInput) > 0.1f) + { + // Get character's current forward direction + const FVector ForwardDirection = GetActorForwardVector(); + + // Apply forward/backward movement + AddMovementInput(ForwardDirection, ForwardInput); + + // Apply turning only when moving (like a car) + if (FMath::Abs(TurnInput) > 0.1f) + { + // Calculate turn rate based on movement speed and turn input + float TurnRate = TurnInput * ShipData.TurnSensitivity * GetWorld()->GetDeltaSeconds(); + + // For backward movement, invert steering (like a real car) + if (ForwardInput < 0.0f) + { + TurnRate *= -1.0f; + } + + // Apply rotation to the character + FRotator NewRotation = GetActorRotation(); + NewRotation.Yaw += TurnRate; + SetActorRotation(NewRotation); + + // Also update controller rotation for camera + if (APlayerController* PC = Cast(Controller)) + { + FRotator ControllerRotation = PC->GetControlRotation(); + ControllerRotation.Yaw += TurnRate; + PC->SetControlRotation(ControllerRotation); + } + } + } } }