Hi, so i have a physics based movement system that works by applying a force. The same thing is also the case for jumping. However, when jumping if I have horizontal momentum(if I am pressing to go forward) every time I touch the ground even while holding down jump button my horizontal momentum gets reduced. I have no idea why this happens and also no idea how to fix it. Does anybody have any idea how I can solve this or just a different approach I should take to jumping or something idk. Here is the code:
if (isGrounded && !isJumping) {
isJumping = true;
//Add jump forces
rb.AddForce(Vector2.up * jumpForce * 1.5f ); // Jump relative to
rb.AddForce(normalVector * jumpForce * 0.5f); // wall jumping? idfk
// If jumping while falling, reset y velocity.
Vector3 vel = rb.linearVelocity;
if (rb.linearVelocity.y < 0.5f) // Reset y velocity if y velocity almost 0
rb.linearVelocity = new Vector3(vel.x, 0, vel.z);
else if (rb.linearVelocity.y > 0) // Half y velocity if y velocity not almost 0
rb.linearVelocity = new Vector3(vel.x, vel.y / 2, vel.z);
}
}