Modify movement implementation for more arcade feel and add strafing

This commit is contained in:
2025-04-15 14:51:25 +05:30
parent 0ba3948af3
commit ca23fd129e
9 changed files with 209 additions and 124 deletions

View File

@@ -6,6 +6,15 @@
#include "Blueprint/UserWidget.h"
#include "SpaceshipPawn.generated.h"
// Movement mode enum to allow switching between different control schemes
UENUM(BlueprintType)
enum class EShipMovementMode : uint8
{
Arcade, // Direct control, minimal inertia
Assisted, // Some inertia with auto-stabilization
Realistic // Full physics with momentum (original)
};
UCLASS()
class MYPROJECT3_API ASpaceshipPawn : public APawn
{
@@ -41,29 +50,45 @@ protected:
// Movement Parameters
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Movement")
float MaxThrust = 2000.0f;
EShipMovementMode MovementMode = EShipMovementMode::Arcade;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Movement")
float ThrustAcceleration = 500.0f;
float MaxSpeed = 2000.0f;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Movement")
float ThrustDeceleration = 500.0f;
float Acceleration = 2000.0f;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Movement")
float RotationSpeed = 100.0f;
float Deceleration = 1500.0f;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Movement")
float RotationSpeed = 5.0f;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Movement")
float MouseSensitivity = 2.0f;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Movement")
float DragCoefficient = 0.05f;
// Auto-stabilization for assisted mode
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Movement", meta = (ClampMin = "0.0", ClampMax = "10.0"))
float StabilizationSpeed = 3.0f;
// How quickly velocity aligns with new direction
// How much momentum to preserve when changing direction (0 = none, 1 = full)
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Movement", meta = (ClampMin = "0.0", ClampMax = "1.0"))
float DirectionalInertia = 0.1f;
// How quickly the ship aligns with its movement direction
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Movement", meta = (ClampMin = "0.0", ClampMax = "10.0"))
float VelocityAlignmentSpeed = 4.0f;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Movement", meta = (ClampMin = "0.0", ClampMax = "1.0", ToolTip = "How much of the current velocity is maintained when changing direction (0 = none, 1 = full)"))
float DirectionalInertia = 0.3f;
// Auto-braking when not thrusting in Arcade mode
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Movement")
bool bAutoBrakeEnabled = true;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Movement")
float AutoBrakeStrength = 3.0f;
// Add a strafe input to allow lateral movement
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Input")
class UInputAction* StrafeAction;
// Shooting properties
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Combat")
@@ -86,14 +111,14 @@ protected:
UUserWidget* CrosshairWidget;
// Input functions
void HandleThrottleStarted(const FInputActionValue& Value);
void HandleThrottleReleased(const FInputActionValue& Value);
void HandleThrottleInput(const FInputActionValue& Value);
void HandleStrafeInput(const FInputActionValue& Value);
void HandleMouseLook(const FInputActionValue& Value);
private:
// Movement state
float CurrentThrust;
float TargetThrust;
float CurrentThrottleInput;
float CurrentStrafeInput;
bool bThrottlePressed;
FVector CurrentVelocity;
FRotator TargetRotation;
@@ -104,10 +129,7 @@ private:
FVector2D MouseDeltaSmoothed;
FVector2D LastMouseDelta;
float MouseSmoothingSpeed = 10.0f;
bool bWasThrottlePressed;
FVector DesiredVelocityDirection;
float MouseSmoothingSpeed = 10.0f;
FTimerHandle FireTimerHandle;
bool bCanFire = true;
@@ -115,4 +137,10 @@ private:
void HandleShoot(const FInputActionValue& Value);
void Fire();
void ResetFire();
// Movement helper functions
void UpdateArcadeMovement(float DeltaTime);
void UpdateAssistedMovement(float DeltaTime);
void UpdateRealisticMovement(float DeltaTime);
void UpdateShipRotation(float DeltaTime);
};