Hello,
I'm trying to make my character jumps configurable, where you can define jump height and duration. I've checked numerous tutorials about that but the calculations shown there don't seem to be accurate.
For example i configured my jump height to be 200px but after checking it ingame it appears to be a bit lower (~188px).
I am not sure if the math formula is inaccurate or maybe i am not taking some of the settings into consideration?
Tracked height debug values:

My example code:
extends KinematicBody2D
# Configuration Variables
var jump_height = 200
var jump_duration = 0.3
# Helper Variables
var current_velocity = Vector2()
var gravity
var jump_velocity
# Debug Variables
var highestposition = 0
var initialposition
func _ready():
gravity = 2 * jump_height / pow(jump_duration, 2)
jump_velocity = -sqrt(2 * gravity * jump_height)
# DEBUG - Save original jump position
initialposition = get_position().y
func _physics_process(delta):
current_velocity.y += gravity * delta
current_velocity = move_and_slide(current_velocity, Vector2(0, -1))
# DEBUG - Track the peak position
var currentpos = initialposition - get_position().y
if currentpos > highestposition:
print(currentpos)
highestposition = currentpos
func _input(event):
if event.is_action_pressed("jump"):
current_velocity.y = jump_velocity
# DEBUG - Reset peak position
highestposition = 0
Any help would be appreciated