Inconsitant jump velocity applied

Hello, I have a springboard area2D object that upon the player colliding with it, applies a set upward velocity. But it’s inconsistent and sometimes varies in height depending on how the player bounces onto it. For example, when I just walk onto it, it seems to function normally but if i jump onto it, the jump becomes dampened. I’m still relatively new to programing so please excuse any glaring oversight I may have neglected.

Relevant Player Code

	if Input.is_action_just_pressed("action") and !Input.is_action_pressed("down") and (is_on_floor() or !$timers/coyote_timer.is_stopped()) and jump_ok and current_state != states.other:
		if spin_ok:
			change_state(states.spinning)
			jump(400)
		elif !spin_ok:
			change_state(states.ascending)
			jump(250)
	
	if !is_on_floor():
		velocity.y += gravity * delta
		if current_state == states.spinning:
			speed = 200
			acceleration = 1
			turn_acceleration = 0.5
			deceleration = 0.5
		else:
			acceleration = 5
			turn_acceleration = 1
			deceleration = 1
		if velocity.y > 0.0 and current_state != states.dive_kicking and current_state != states.spinning:
			change_state(states.descending)
		
		if Input.is_action_just_pressed("action") and Input.is_action_pressed("down") and $timers/dive_timer.is_stopped() and current_state != states.dive_kicking:
			change_state(states.dive_kicking)
			velocity.x = last_dir * 350
			velocity.y += 250
			if velocity.x > 0:
		
				$AnimatedSprite2D.flip_h = false
			elif velocity.x < 0:
				$AnimatedSprite2D.flip_h = true
	
	var was_on_floor = is_on_floor()
	move_and_slide()
	
	if current_state != states.ascending and !is_on_floor() and was_on_floor and jump_ok:
		$timers/coyote_timer.start()

func jump(x):
	jump_ok = false
	velocity.y -= x

Springboard Code

extends StaticBody2D

func _on_area_2d_body_entered(body):
	if body.is_in_group("player"):
			body.jump(450)
			body.change_state(body.states.other)

My states strictly control animations and bare no relevance on the player physics.

Using velocity.y -= x inside jump() will just subtract from your current velocity. If you want the same jump height no matter the previous velocity, you should use velocity.y = -x instead.

1 Like