Character Falls Faster When Not Jumping

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By BiLLz

Hey all!

So in my platformer code, my character jumps just fine. However, when he just walks off an edge, he falls a lot faster than when he is jumping. I am implementing my jumping by having a jumpForce variable, a gravity variable, and then constantly adding the gravity to the player’s movement:

//apply the gravity
	movement.y += gravity;
	
	//check for input
	if (Input.IsActionPressed("moveRight"))
	{
		movement.x = moveSpeed;
		isFacingRight = true;
	}
	else if (Input.IsActionPressed("moveLeft"))
	{
		movement.x = -moveSpeed;
		isFacingRight = false;
	}
	else
	{
		movement.x = 0;
	}

	if (IsOnFloor())
	{
		if (Input.IsActionJustPressed("moveJump"))
		{
			//set the jump force
			movement.y = -jumpForce;
		}
	}
	
	MoveAndSlide(movement, upDirection);

Is there a better way to fo about this so that the player doesn’t just fall quickly off of the platforms?

Thank you!

:bust_in_silhouette: Reply From: njamster

You’re not using the return-value of move_and_slide so movement grows bigger and bigger in y-direction each frame due to gravity. As long as the platform blocks the way, that has no consequences, but once you move off of it, you’ll fall with full momentum! It’s easy to fix though: `movement = MoveAndSlide(movement, upDirection);