From 88cbe5910ca2198a52471da6b4d1fb9f2ccc211c Mon Sep 17 00:00:00 2001 From: Kevin Poretti Date: Sat, 26 Mar 2022 22:20:41 -0400 Subject: [PATCH] Scale current lateral velocity by input direction when jumping (not working) --- .../Characters/Protagonist/BP_NewProtag.uasset | 4 ++-- .../Components/SNGCharacterMovementComponent.cpp | 11 +++++++++-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/SwordNGun/Content/Characters/Protagonist/BP_NewProtag.uasset b/SwordNGun/Content/Characters/Protagonist/BP_NewProtag.uasset index f50171a..060ff03 100644 --- a/SwordNGun/Content/Characters/Protagonist/BP_NewProtag.uasset +++ b/SwordNGun/Content/Characters/Protagonist/BP_NewProtag.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:9273c229169b5e443f8b740b5a90ba8f1dbfa3f6c6f8efd92351340495a85d71 -size 184558 +oid sha256:aef189a5b0e1a32380af6cfc08348ef362eea940f51b91d3737a19fc3dc6b47d +size 184851 diff --git a/SwordNGun/Source/SwordNGun/Private/Components/SNGCharacterMovementComponent.cpp b/SwordNGun/Source/SwordNGun/Private/Components/SNGCharacterMovementComponent.cpp index 44054ce..e468e77 100644 --- a/SwordNGun/Source/SwordNGun/Private/Components/SNGCharacterMovementComponent.cpp +++ b/SwordNGun/Source/SwordNGun/Private/Components/SNGCharacterMovementComponent.cpp @@ -208,7 +208,8 @@ bool USNGCharacterMovementComponent::DoJump(bool bReplayingMoves) FLaunchParameters JumpParams; FVector WorldInputDir = CharacterOwnerAsSNGChar->GetInputAsWorldDirection(); - if(WorldInputDir.Size2D() >= CharacterOwnerAsSNGChar->GetInputThreshold()) + bool InputThresholdMet = WorldInputDir.Size2D() >= CharacterOwnerAsSNGChar->GetInputThreshold(); + if(InputThresholdMet) { FVector JumpLateralVelocity = WorldInputDir * DefaultJumpLateralVelocity; JumpParams.Velocity.X = JumpLateralVelocity.X; @@ -221,7 +222,13 @@ bool USNGCharacterMovementComponent::DoJump(bool bReplayingMoves) JumpParams.bOverrideY = false; JumpParams.bOverrideZ = true; - JumpParams.VelocityScale = FVector(LateralVelocityScaling, 1.0f); + /** + * NOTE(kevin): This is done so that if the player holds nothing the character still carries some lateral + * momentum out of a neutral jump. If the player if moving forward but jumps right (this is all relative + * to the camera) we want all forward momentum canceled and the character to only have velocity going + * up and right. + */ + JumpParams.VelocityScale = FVector(InputThresholdMet ? FVector2D(WorldInputDir.X, WorldInputDir.Y) * LateralVelocityScaling : LateralVelocityScaling, 1.0f); JumpParams.bUseDefaultGroundFriction = true; JumpParams.bUseDefaultGravityScale = true;