Implement our own Launch function so we have control over whether the movement mode changes

This commit is contained in:
Kevin Poretti 2022-03-25 21:00:02 -04:00
parent 01df25063c
commit 811d3329cb
7 changed files with 84 additions and 15 deletions

Binary file not shown.

View File

@ -78,10 +78,12 @@ void USNGCharacterMovementComponent::RestoreMovementDefaults()
void USNGCharacterMovementComponent::Dash()
{
GroundFriction = DashGroundFriction;
GravityScale = DashGravityScale;
FloatTime = DashFloatTime;
SlideTime = DashSlideTime;
FLaunchParameters LaunchParams;
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;
@ -92,7 +94,9 @@ void USNGCharacterMovementComponent::Dash()
FRotator CharacterRot = FRotator(0.0f, GetCharacterOwner()->GetActorRotation().Yaw, 0.0f);
FVector LaunchDir = FVector(UKismetMathLibrary::GetForwardVector(CharacterRot));
LaunchDir.Normalize();
Launch(LaunchDir * DashVelocity);
LaunchParams.Velocity = LaunchDir * DashVelocity;
LaunchCharacter(LaunchParams);
}
#if WITH_EDITOR
@ -124,6 +128,21 @@ void USNGCharacterMovementComponent::OnSprintTimer()
TargetMaxWalkSpeed = SprintingMaxWalkSpeed;
}
void USNGCharacterMovementComponent::LaunchCharacter(FLaunchParameters& LaunchParams)
{
GroundFriction = LaunchParams.GroundFriction;
GravityScale = LaunchParams.GravityScale;
FloatTime = LaunchParams.FloatTime;
SlideTime = LaunchParams.SlideTime;
Velocity = LaunchParams.Velocity;
if(LaunchParams.bOverrideMovementMode)
{
SetMovementMode(LaunchParams.NewMovementMode);
}
}
void USNGCharacterMovementComponent::ComputeGravityScaleAndJumpZVelocity()
{
float HalfJumpDuration = DesiredJumpDuration / 2.0f;
@ -206,6 +225,8 @@ void USNGCharacterMovementComponent::TickComponent(float DeltaTime, ELevelTick T
{
Super::TickComponent(DeltaTime, Tick, ThisTickFunction);
// turning off sprinting for now...not a HUGE fan of this implementation
/*
float LateralSpeed = Velocity.Size2D();
if(LateralSpeed >= SprintLateralSpeedThreshold && !GetWorld()->GetTimerManager().IsTimerActive(TimerHandle_SprintTimer))
{
@ -224,6 +245,7 @@ void USNGCharacterMovementComponent::TickComponent(float DeltaTime, ELevelTick T
TargetMaxWalkSpeed = DefaultMaxWalkSpeed;
MaxWalkSpeedInterpSpeed = WalkToSprintInterpSpeed;
}
*/
InterpolateMovementParameters(DeltaTime);
}

View File

@ -6,6 +6,51 @@
#include "GameFramework/CharacterMovementComponent.h"
#include "SNGCharacterMovementComponent.generated.h"
USTRUCT(BlueprintType)
struct FLaunchParameters
{
GENERATED_BODY()
/** Velocity */
UPROPERTY()
FVector Velocity;
/** Should the character's movement mode change after being launched? */
UPROPERTY(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)
TEnumAsByte<EMovementMode> NewMovementMode;
/** The ground friction that should be immediately applied when the character is launched */
UPROPERTY(BlueprintReadWrite)
float GroundFriction;
/** The gravity scale that should be immediately applied when the character is launched */
UPROPERTY(BlueprintReadWrite)
float GravityScale;
/** The float time that should be immediately applied when the character is launched */
UPROPERTY(BlueprintReadWrite)
float FloatTime;
/** The slide time that should be immediately applied when the character is launched */
UPROPERTY(BlueprintReadWrite)
float SlideTime;
FLaunchParameters()
: Velocity(FVector::ZeroVector)
, bOverrideMovementMode(false)
, NewMovementMode(EMovementMode::MOVE_Walking)
, GroundFriction(8.0f)
, GravityScale(1.0f)
, FloatTime(0.0f)
, SlideTime(0.0f)
{
}
};
/**
* Class that extends UE CharacterMovementComponent to add SNG specific functionality
*
@ -134,6 +179,8 @@ 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.