Multiple problems with jumping/bouncing

extends CharacterBody2D

@export var jump_count : int = 0
var current_jump_count : int
@export var SPEED = 150.0
@export var JUMP_VELOCITY = -200.0

Get the gravity from the project settings to be synced with RigidBody nodes.

var gravity = ProjectSettings.get_setting(“physics/2d/default_gravity”)

func _physics_process(delta):
if not is_on_floor():
velocity.y += gravity * delta
if Input.is_action_just_pressed(“spacebar”) and is_on_floor():
velocity.y = JUMP_VELOCITY
current_jump_count += 1

var collision = move_and_collide(velocity * delta)
if collision and current_jump_count >= 1 :
	velocity = velocity.bounce(collision.get_normal())
	velocity.y *= 2.2
	jump_count -= 1
	if velocity.y < -10:
		print_debug("I am jumping! Velocity = " + str(velocity.y))
	
	
	
if collision and current_jump_count >= 1 :
	current_jump_count -= 1
	jump_count -= 1
	
	
if current_jump_count and jump_count >= 1:
	
	current_jump_count -= 1
	jump_count -= 1
	


var direction = Input.get_axis("left", "right")
if direction:
	velocity.x = direction * SPEED
else:
	velocity.x = move_toward(velocity.x, 0, SPEED)

move_and_slide()

I have multiples questions if its not too much of a hassle:

  1. when jumping from a higher height the player jumps DUPER high, how can i cap the height of the player?
  2. Sometimes when jumping from a higher platform the player does not jump but instead keeps the jump and uses it when landing on the higher surface again when landing, how do i stop this?

Hi. Not a worry, but I’m not sure that I understand the intention here so I have a few questions to ask you as well.

  1. I see you have jump_count and current_jump_count. What is the difference between the two? Is jump_count supposed to limit the maximum number of air jumps?

  2. What is your intended collision behaviour while airbourne? It looks like you are going for a bounce in which the vertical (y) component gets a big boost? It could be the reason for the behaviour you desribe in question 2.

  3. What do you mean in your first question about jumping from a higher height? Do you mean when the player jumps in the air?