From 32531fbcf4add617047c818488d66ac420d4e5dd Mon Sep 17 00:00:00 2001 From: Kevin Poretti Date: Sat, 26 Mar 2022 15:43:53 -0400 Subject: [PATCH] Add more options to launch parameters and update jump so it uses our own launch function --- .../Locomotion/Fighter_Jump_B_Montage.uasset | 4 +- .../NEW/Locomotion/Fighter_Jump_B_loop.uasset | 3 + .../Locomotion/Fighter_Jump_F_Montage.uasset | 4 +- .../Locomotion/Fighter_Jump_Montage.uasset | 4 +- .../OLD/Mesh/UE4_Mannequin_Skeleton.uasset | 4 +- SwordNGun/Content/Maps/MovementTest.umap | 2 +- .../SNGCharacterMovementComponent.cpp | 81 ++++++++++++---- .../SNGCharacterMovementComponent.h | 95 ++++++++++++++----- 8 files changed, 145 insertions(+), 52 deletions(-) create mode 100644 SwordNGun/Content/Characters/Protagonist/Animations/NEW/Locomotion/Fighter_Jump_B_loop.uasset diff --git a/SwordNGun/Content/Characters/Protagonist/Animations/NEW/Locomotion/Fighter_Jump_B_Montage.uasset b/SwordNGun/Content/Characters/Protagonist/Animations/NEW/Locomotion/Fighter_Jump_B_Montage.uasset index d727772..4ee4334 100644 --- a/SwordNGun/Content/Characters/Protagonist/Animations/NEW/Locomotion/Fighter_Jump_B_Montage.uasset +++ b/SwordNGun/Content/Characters/Protagonist/Animations/NEW/Locomotion/Fighter_Jump_B_Montage.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:872d751ab0275c9f23ac9c13b8b4d6956694bdae602a6ec2716607d488561f76 -size 101677 +oid sha256:a64801201c9ad026d759917e09d8672dea95b90b5817625965eb4e597c6f4d11 +size 101556 diff --git a/SwordNGun/Content/Characters/Protagonist/Animations/NEW/Locomotion/Fighter_Jump_B_loop.uasset b/SwordNGun/Content/Characters/Protagonist/Animations/NEW/Locomotion/Fighter_Jump_B_loop.uasset new file mode 100644 index 0000000..354e3b4 --- /dev/null +++ b/SwordNGun/Content/Characters/Protagonist/Animations/NEW/Locomotion/Fighter_Jump_B_loop.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:94543267049cbeb041a60d806293f99fbe7136b844712767b1f88d4c8854ce9a +size 138315 diff --git a/SwordNGun/Content/Characters/Protagonist/Animations/NEW/Locomotion/Fighter_Jump_F_Montage.uasset b/SwordNGun/Content/Characters/Protagonist/Animations/NEW/Locomotion/Fighter_Jump_F_Montage.uasset index bf70538..eb9b3e5 100644 --- a/SwordNGun/Content/Characters/Protagonist/Animations/NEW/Locomotion/Fighter_Jump_F_Montage.uasset +++ b/SwordNGun/Content/Characters/Protagonist/Animations/NEW/Locomotion/Fighter_Jump_F_Montage.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:25eedcc2e12e6a9a131779b57f23b5f82b2107bf05b83d906e1505a82dcf5473 -size 101677 +oid sha256:1559f9030c485e17682ba6c1fd8f79bb436a4e8a23b9fcffec679990a005465e +size 101981 diff --git a/SwordNGun/Content/Characters/Protagonist/Animations/NEW/Locomotion/Fighter_Jump_Montage.uasset b/SwordNGun/Content/Characters/Protagonist/Animations/NEW/Locomotion/Fighter_Jump_Montage.uasset index 5f4b515..c5d4f02 100644 --- a/SwordNGun/Content/Characters/Protagonist/Animations/NEW/Locomotion/Fighter_Jump_Montage.uasset +++ b/SwordNGun/Content/Characters/Protagonist/Animations/NEW/Locomotion/Fighter_Jump_Montage.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:7417a7c36a1e1e3ed36bcd8ec3c92b6377ae0b2b03499d9f7c541e818e62718c -size 101572 +oid sha256:69acb83754cc839a858d683f1135dffd7c48790b5b32014c5f34fc815447fcfe +size 102024 diff --git a/SwordNGun/Content/Characters/Protagonist/Character/OLD/Mesh/UE4_Mannequin_Skeleton.uasset b/SwordNGun/Content/Characters/Protagonist/Character/OLD/Mesh/UE4_Mannequin_Skeleton.uasset index c350de6..5bce5a4 100644 --- a/SwordNGun/Content/Characters/Protagonist/Character/OLD/Mesh/UE4_Mannequin_Skeleton.uasset +++ b/SwordNGun/Content/Characters/Protagonist/Character/OLD/Mesh/UE4_Mannequin_Skeleton.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:abe99721461b0fbce2576ec2fef40187a4dbdbe98d2651908d48d9c3f98e4dae -size 31538 +oid sha256:e258977c54afff014fe0166665b84e7fbf90c0ca03e8ffeb037f83195ce664aa +size 31608 diff --git a/SwordNGun/Content/Maps/MovementTest.umap b/SwordNGun/Content/Maps/MovementTest.umap index 8a265b3..dd8bc88 100644 --- a/SwordNGun/Content/Maps/MovementTest.umap +++ b/SwordNGun/Content/Maps/MovementTest.umap @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:9bbf11ffd9f17ef306ffeb9acc178712e96b81dc426477c35b4b045385f21e5c +oid sha256:8abecb097959ca5b3ad604935452a0da2425870177a6aaaaecd6ae0de3ce27ef size 949560 diff --git a/SwordNGun/Source/SwordNGun/Private/Components/SNGCharacterMovementComponent.cpp b/SwordNGun/Source/SwordNGun/Private/Components/SNGCharacterMovementComponent.cpp index f38d392..baeab38 100644 --- a/SwordNGun/Source/SwordNGun/Private/Components/SNGCharacterMovementComponent.cpp +++ b/SwordNGun/Source/SwordNGun/Private/Components/SNGCharacterMovementComponent.cpp @@ -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) diff --git a/SwordNGun/Source/SwordNGun/Public/Components/SNGCharacterMovementComponent.h b/SwordNGun/Source/SwordNGun/Public/Components/SNGCharacterMovementComponent.h index e570a1d..8f4a816 100644 --- a/SwordNGun/Source/SwordNGun/Public/Components/SNGCharacterMovementComponent.h +++ b/SwordNGun/Source/SwordNGun/Public/Components/SNGCharacterMovementComponent.h @@ -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 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"))