Add more options to launch parameters and update jump so it uses our own launch function

This commit is contained in:
Kevin Poretti 2022-03-26 15:43:53 -04:00
parent 811d3329cb
commit 32531fbcf4
8 changed files with 145 additions and 52 deletions

BIN
SwordNGun/Content/Maps/MovementTest.umap (Stored with Git LFS)

Binary file not shown.

View File

@ -79,12 +79,16 @@ void USNGCharacterMovementComponent::RestoreMovementDefaults()
void USNGCharacterMovementComponent::Dash()
{
FLaunchParameters LaunchParams;
LaunchParams.bOverrideX = true;
LaunchParams.bOverrideY = true;
LaunchParams.bOverrideZ = true;
LaunchParams.bOverrideMovementMode = false;
LaunchParams.GroundFriction = DashGroundFriction;
LaunchParams.GravityScale = DashGravityScale;
LaunchParams.FloatTime = DashFloatTime;
LaunchParams.SlideTime = DashSlideTime;
// sets gravity and friction targets which will start interpolating after float time and slide time elapse respectively
TargetGravityScale = DefaultGravityScale;
TargetGroundFriction = DefaultGroundFriction;
@ -128,14 +132,42 @@ void USNGCharacterMovementComponent::OnSprintTimer()
TargetMaxWalkSpeed = SprintingMaxWalkSpeed;
}
void USNGCharacterMovementComponent::LaunchCharacter(FLaunchParameters& LaunchParams)
void USNGCharacterMovementComponent::LaunchCharacter(const FLaunchParameters LaunchParams)
{
GroundFriction = LaunchParams.GroundFriction;
GravityScale = LaunchParams.GravityScale;
Velocity *= LaunchParams.VelocityScale;
//
if(LaunchParams.bOverrideX)
{
Velocity.X = LaunchParams.Velocity.X;
}
else
{
Velocity.X += LaunchParams.Velocity.X;
}
if(LaunchParams.bOverrideY)
{
Velocity.Y = LaunchParams.Velocity.Y;
}
else
{
Velocity.Y += LaunchParams.Velocity.Y;
}
if(LaunchParams.bOverrideZ)
{
Velocity.Z = LaunchParams.Velocity.Z;
}
else
{
Velocity.Z += LaunchParams.Velocity.Z;
}
GroundFriction = LaunchParams.bUseDefaultGroundFriction ? DefaultGroundFriction : LaunchParams.GroundFriction;
GravityScale = LaunchParams.bUseDefaultGravityScale ? DefaultGravityScale : LaunchParams.GravityScale;
FloatTime = LaunchParams.FloatTime;
SlideTime = LaunchParams.SlideTime;
Velocity = LaunchParams.Velocity;
if(LaunchParams.bOverrideMovementMode)
{
@ -153,25 +185,32 @@ void USNGCharacterMovementComponent::ComputeGravityScaleAndJumpZVelocity()
DefaultGravityScale = TargetGravity / GameGravity;
}
void USNGCharacterMovementComponent::StartJump()
bool USNGCharacterMovementComponent::DoJump(bool bReplayingMoves)
{
/*
JumpTimer = MaxJumpTime;
Velocity = FVector(Velocity.X * LateralVelocityDampening, Velocity.Y * LateralVelocityDampening, 0.0f);
*/
}
void USNGCharacterMovementComponent::AddJumpForce()
{
/*
if(JumpTimer > 0.0f)
if ( CharacterOwner && CharacterOwner->CanJump() )
{
Velocity = FVector(Velocity.X, Velocity.Y, Velocity.Z + (JumpForce * GetWorld()->DeltaTimeSeconds));
// Don't jump if we can't move up/down.
if (!bConstrainToPlane || FMath::Abs(PlaneConstraintNormal.Z) != 1.f)
{
JumpTimer = FMath::Max(JumpTimer - GetWorld()->DeltaTimeSeconds, 0.0f);
FLaunchParameters JumpParams;
JumpParams.Velocity.Z = DefaultJumpZVelocity;
JumpParams.bOverrideX = false;
JumpParams.bOverrideY = false;
JumpParams.bOverrideZ = true;
JumpParams.bUseDefaultGroundFriction = true;
JumpParams.bUseDefaultGravityScale = true;
JumpParams.bOverrideMovementMode = true;
JumpParams.NewMovementMode = EMovementMode::MOVE_Falling;
LaunchCharacter(JumpParams);
return true;
}
}
*/
return false;
}
void USNGCharacterMovementComponent::InterpolateMovementParameters(float DeltaTime)

View File

@ -11,39 +11,87 @@ struct FLaunchParameters
{
GENERATED_BODY()
/** Velocity */
UPROPERTY()
/** Velocity to either add or set for this character */
UPROPERTY(EditAnywhere, BlueprintReadWrite)
FVector Velocity;
/**
* How much to scale current velocity by. Set all components to 1 if you want the character to keep whatever
* velocity they currently have.
*/
UPROPERTY(EditAnywhere, BlueprintReadWrite)
FVector VelocityScale;
/**
* Should the X component of character's velocity be overriden with Velocity parameter or added?
* Default is false which means Velocity X component will be added to current character's velocity
*/
UPROPERTY(EditAnywhere, BlueprintReadWrite)
bool bOverrideX;
/**
* Should the Y component of character's velocity be overriden with Velocity parameter or added?
* Default is false which means Velocity Y component will be added to current character's velocity
*/
UPROPERTY(EditAnywhere, BlueprintReadWrite)
bool bOverrideY;
/**
* Should the Z component of character's velocity be overriden with Velocity parameter or added?
* Default is false which means Velocity Z component will be added to current character's velocity
*/
UPROPERTY(EditAnywhere, BlueprintReadWrite)
bool bOverrideZ;
/** Should the character's movement mode change after being launched? */
UPROPERTY(BlueprintReadWrite)
UPROPERTY(EditAnywhere, BlueprintReadWrite)
bool bOverrideMovementMode;
/** What the character's movement mode will be set to after launch. This will only be set is bOverrideMovementMode is true. */
UPROPERTY(BlueprintReadWrite)
UPROPERTY(EditAnywhere, BlueprintReadWrite)
TEnumAsByte<EMovementMode> NewMovementMode;
/**
* GroundFriction will be overriden to DefaultGroundFriction as specified in the character movement
* component instead of what is supplied in this struct.
*/
UPROPERTY(EditAnywhere, BlueprintReadWrite)
bool bUseDefaultGroundFriction;
/** The ground friction that should be immediately applied when the character is launched */
UPROPERTY(BlueprintReadWrite)
UPROPERTY(EditAnywhere, BlueprintReadWrite)
float GroundFriction;
/**
* GravityScale will be overriden to DefaultGravityScale as specified in the character movement
* component instead of what is supplied in this struct.
*/
UPROPERTY(EditAnywhere, BlueprintReadWrite)
bool bUseDefaultGravityScale;
/** The gravity scale that should be immediately applied when the character is launched */
UPROPERTY(BlueprintReadWrite)
UPROPERTY(EditAnywhere, BlueprintReadWrite)
float GravityScale;
/** The float time that should be immediately applied when the character is launched */
UPROPERTY(BlueprintReadWrite)
UPROPERTY(EditAnywhere, BlueprintReadWrite)
float FloatTime;
/** The slide time that should be immediately applied when the character is launched */
UPROPERTY(BlueprintReadWrite)
UPROPERTY(EditAnywhere, BlueprintReadWrite)
float SlideTime;
FLaunchParameters()
: Velocity(FVector::ZeroVector)
, VelocityScale(FVector::OneVector)
, bOverrideX(false)
, bOverrideY(false)
, bOverrideZ(false)
, bOverrideMovementMode(false)
, NewMovementMode(EMovementMode::MOVE_Walking)
, bUseDefaultGroundFriction(false)
, GroundFriction(8.0f)
, bUseDefaultGravityScale(false)
, GravityScale(1.0f)
, FloatTime(0.0f)
, SlideTime(0.0f)
@ -74,6 +122,21 @@ public:
UFUNCTION(BlueprintCallable)
void RestoreMovementDefaults();
/**
* @brief Sets and scales current character's velocity and sets other movement values specified in the passed LaunchParams.
* The order of operations for updating velocity is:
* 1) Multiply current velocity by VelocityScale
* 2) Will either set or add to current velocity components with the value specified in LaunchParams.Velocity
* @param LaunchParams - settings on how this character should be launched. See documentation for FLaunchParameters
* for more information.
*/
UFUNCTION(BlueprintCallable, meta=(AutoCreateRefTerm="LaunchParams"))
void LaunchCharacter(const FLaunchParameters LaunchParams);
/**
* @brief Sets up launch parameters and character movement parameter targets and finally launches the character
* for the character to dash.
*/
UFUNCTION(BlueprintCallable)
void Dash();
@ -179,8 +242,6 @@ protected:
/** Timer used to determine when to start interpolating GravityScale back to TargetGravityScale */
UPROPERTY(BlueprintReadWrite)
float FloatTime;
void LaunchCharacter(FLaunchParameters& LaunchParams);
/**
* How high (Z) is the character able to reach when holding the jump button for the maximum allowed time.
@ -213,17 +274,7 @@ protected:
void ComputeGravityScaleAndJumpZVelocity();
/**
* Sets up character velocities and jump parameters like the jump timer
*/
UFUNCTION(BlueprintCallable)
void StartJump();
/**
* Continuously applies an upward force to the character as the jump button is held down
*/
UFUNCTION(BlueprintCallable)
void AddJumpForce();
virtual bool DoJump(bool bReplayingMoves) override;
/** Default friction when not performing any special actions and in the air */
UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category="SNG Character Movement|Defaults|Air", meta=(ClampMin="0", UIMin="0"))