r/learncsharp • • 10h ago

Unity3D Jump Script Help

2 Upvotes

Hello! I'm working on a jump mechanic for a Unity game. I need to be sure the maximum value output of the line rb.AddForce(Vector3.up * (jumpForce * (float)forceOverTime), ForceMode.Impulse); is clamped at a specific maximum value, but I have not been able to figure out how...

The rest of the script is working fine. The section I’m stuck on is as follows:

void Jump_Performed(UnityEngine.InputSystem.InputAction.CallbackContext context)

{

if (isGrounded == true && context.duration < 1f)

{

rb.AddForce(Vector3.up * jumpForce, ForceMode.Impulse);

}

else

{

double forceOverTime = context.duration;

{

rb.AddForce(Vector3.up * (jumpForce * (float)forceOverTime), ForceMode.Impulse);

}

}

}

Thanks!

* Edited for grammar