Skip to content

Commit b74f9f8

Browse files
committed
Fix jump height based on wanted speed instead of actual speed
1 parent 4c448eb commit b74f9f8

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/CharacterControllerV2/DCLCharacterControllerV2.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ internal class DCLCharacterControllerV2
6464

6565
private CameraMode.ModeId[] tpsCameraModes = new[] { CameraMode.ModeId.ThirdPersonRight, CameraMode.ModeId.ThirdPersonLeft, CameraMode.ModeId.ThirdPersonCenter };
6666
private int currentCameraMode = 0;
67+
private Vector3 lastFinalVelocityBasedOnActualMovement;
6768

6869
public DCLCharacterControllerV2(ICharacterView view, CharacterControllerData data, IInputActionHold jumpAction, IInputActionHold sprintAction, InputAction_Hold walkAction,
6970
IInputActionMeasurable characterXAxis,
@@ -163,6 +164,7 @@ public void Update(float deltaTime)
163164
lastUngroundPeakHeight = view.GetPosition().y;
164165

165166
lastFinalVelocity = finalVelocity;
167+
lastFinalVelocityBasedOnActualMovement = lastFinalVelocity.normalized * (Flat(deltaPosition).magnitude / Time.deltaTime);
166168

167169
Vector3 slope = GetSlopeModifier();
168170
lastSlopeDelta = slope * (data.slipSpeedMultiplier * Time.deltaTime);
@@ -396,7 +398,7 @@ private void CalculateVerticalVelocity(float deltaTime)
396398
if (CanJump())
397399
{
398400
characterState.Jump();
399-
float jumpHeight = GetJumpHeight(Flat(lastFinalVelocity));
401+
float jumpHeight = GetJumpHeight(Flat(lastFinalVelocityBasedOnActualMovement));
400402
float jumpStr = Mathf.Sqrt(-2 * jumpHeight * (data.gravity * data.jumpGravityFactor));
401403
velocity.y += jumpStr;
402404
/*var jumpImpulse = new Vector3(velocity.x, jumpStr, velocity.z);
@@ -536,7 +538,7 @@ private float GetJumpHeight(Vector3 flatHorizontalVelocity)
536538

537539
float currentSpeed = flatHorizontalVelocity.magnitude;
538540
float jumpHeight = Mathf.Lerp(data.jogJumpHeight, maxJumpHeight, currentSpeed / data.runSpeed);
539-
return jumpHeight;
541+
return jumpHeight;
540542
}
541543

542544
public CharacterState GetCharacterState() =>

0 commit comments

Comments
 (0)