So, like the title says i cant manage to make the player jump while moving, i have placed a print before everything to see what happens, and from what i see isGrounded is true while idle and its ok and normal, but it become false when moving except sometime that it become true(so its random), so the game for some reason when the player moves thinks that the player is in the air, even tho its not.
Im not using a rigid body, only a character controller.
Here’s the jump code:
Variables regarding the jump
[Header("Gravity")]
[SerializeField] float gravity = 9.8f;
[SerializeField] float gravityMultiplier = 2;
[SerializeField] float groundedGravity = -0.5f;
[SerializeField] float jumpHeight = 3f;
float velocityY;
Jump code
void GravityAndJump()
{
print(controller.isGrounded);
print(velocityY);
//apply groundedGravity when the Player is Grounded
if (controller.isGrounded && velocityY < 0f)
velocityY = groundedGravity;
//When Grounded and Jump Button is Pressed, set veloctiyY with the formula below
if (controller.isGrounded && Input.GetKeyDown(KeyCode.Space))
{
velocityY = Mathf.Sqrt(jumpHeight * 2f * gravity);
}
//applying gravity when Player is not grounded
velocityY -= gravity * gravityMultiplier * Time.deltaTime;
controller.Move(Vector3.up * velocityY * Time.deltaTime);
}