更新小船操作逻辑
This commit is contained in:
parent
73bda7f568
commit
c9434d19a3
File diff suppressed because it is too large
Load Diff
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -10,6 +10,7 @@
|
|||||||
#include "Components/CapsuleComponent.h"
|
#include "Components/CapsuleComponent.h"
|
||||||
#include "GameFramework/CharacterMovementComponent.h"
|
#include "GameFramework/CharacterMovementComponent.h"
|
||||||
#include "GameFramework/SpringArmComponent.h"
|
#include "GameFramework/SpringArmComponent.h"
|
||||||
|
#include "Kismet/KismetMathLibrary.h"
|
||||||
#include "ProjectFish/Components/ShipSpringArmComponent.h"
|
#include "ProjectFish/Components/ShipSpringArmComponent.h"
|
||||||
|
|
||||||
|
|
||||||
@ -65,7 +66,8 @@ AShipbase::AShipbase()
|
|||||||
void AShipbase::BeginPlay()
|
void AShipbase::BeginPlay()
|
||||||
{
|
{
|
||||||
Super::BeginPlay();
|
Super::BeginPlay();
|
||||||
|
MoveForward = GetActorForwardVector();
|
||||||
|
MoveRight = GetActorRightVector();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Called every frame
|
// Called every frame
|
||||||
@ -154,48 +156,54 @@ void AShipbase::Move(const FInputActionValue& Value)
|
|||||||
// AddMovementInput(ForwardDirection, MovementVector.Y);
|
// AddMovementInput(ForwardDirection, MovementVector.Y);
|
||||||
// AddMovementInput(RightDirection, MovementVector.X);
|
// AddMovementInput(RightDirection, MovementVector.X);
|
||||||
// }
|
// }
|
||||||
//修改移动转向逻辑
|
|
||||||
if (Controller != nullptr)
|
|
||||||
{
|
|
||||||
// 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)
|
// if (Controller != nullptr)
|
||||||
{
|
// {
|
||||||
// Get character's current forward direction
|
// // Store input values
|
||||||
const FVector ForwardDirection = GetActorForwardVector();
|
// 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 only, not the controller
|
||||||
|
// FRotator NewRotation = GetActorRotation();
|
||||||
|
// NewRotation.Yaw += TurnRate;
|
||||||
|
// SetActorRotation(NewRotation);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
// Apply forward/backward movement
|
//第三版移动逻辑:WASD控制转向和移动
|
||||||
AddMovementInput(ForwardDirection, ForwardInput);
|
FVector TargetDirec = (MovementVector.Y * MoveForward + MovementVector.X * MoveRight).GetSafeNormal();
|
||||||
|
FRotator TargetRot = FRotationMatrix::MakeFromX(TargetDirec).Rotator();
|
||||||
|
|
||||||
|
FRotator CurrentRot = GetActorRotation();
|
||||||
|
FRotator NewRotator = FMath::RInterpTo(CurrentRot, TargetRot, GetWorld()->GetDeltaSeconds(), ShipData.TurnSensitivity);
|
||||||
|
SetActorRotation(NewRotator);
|
||||||
|
AddMovementInput(GetActorForwardVector(), FMath::Max(FMath::Abs(MovementVector.Y ), FMath::Abs(MovementVector.X)));
|
||||||
|
|
||||||
// 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 only, not the controller
|
|
||||||
FRotator NewRotation = GetActorRotation();
|
|
||||||
NewRotation.Yaw += TurnRate;
|
|
||||||
SetActorRotation(NewRotation);
|
|
||||||
// // Also update controller rotation for camera
|
|
||||||
// if (APlayerController* PC = Cast<APlayerController>(Controller))
|
|
||||||
// {
|
|
||||||
// FRotator ControllerRotation = PC->GetControlRotation();
|
|
||||||
// ControllerRotation.Yaw += TurnRate;
|
|
||||||
// PC->SetControlRotation(ControllerRotation);
|
|
||||||
// }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void AShipbase::Look(const FInputActionValue& Value)
|
void AShipbase::Look(const FInputActionValue& Value)
|
||||||
|
|||||||
@ -52,6 +52,10 @@ protected:
|
|||||||
void ApplyMovementSettings();
|
void ApplyMovementSettings();
|
||||||
void ApplyCameraSettings();
|
void ApplyCameraSettings();
|
||||||
|
|
||||||
|
private:
|
||||||
|
FVector MoveForward;
|
||||||
|
FVector MoveRight;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
UPROPERTY(EditAnywhere,BlueprintReadOnly, Category= "Config", meta = (AllowPrivateAccess = "true"))
|
UPROPERTY(EditAnywhere,BlueprintReadOnly, Category= "Config", meta = (AllowPrivateAccess = "true"))
|
||||||
FShipDataConfig ShipData;
|
FShipDataConfig ShipData;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user