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

View File

@ -6,6 +6,51 @@
#include "GameFramework/CharacterMovementComponent.h" #include "GameFramework/CharacterMovementComponent.h"
#include "SNGCharacterMovementComponent.generated.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 * Class that extends UE CharacterMovementComponent to add SNG specific functionality
* *
@ -135,6 +180,8 @@ protected:
UPROPERTY(BlueprintReadWrite) UPROPERTY(BlueprintReadWrite)
float FloatTime; 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. * How high (Z) is the character able to reach when holding the jump button for the maximum allowed time.
* *