How could I make a jump that takes the velocity or movement of the character? (horizontally)

Godot Version

Godot_v4.1.3 for Windows

Question

How would i accomplish making a jump that takes the horizontal movement velocity and makes your jump that fast? I would know how to do this, but there is one major problem.

	var input_dir = Input.get_vector("left", "right", "up", "down")
	var direction = (head.transform.basis * Vector3(input_dir.x, 0, input_dir.y)).normalized()
	if direction:
		velocity.x = direction.x * speed
		velocity.z = direction.z * speed
	else: 
		velocity.x = 0.0
		velocity.z = 0.0

This is the code that does the movement
If we did not set the velocity.x and z to 0, the ground appears to be very slippery
jumping one (simple, really)

		isJumping = true
		velocity.y = JUMP_VELOCITY
		velocity.x = speed;
		velocity.z = speed;

Just to let the mods or whoever decides to answer this know, it extends CharacterBody3D
peace

this is fine but if you like the pro gamer move fiction you can use:

		velocity.x = move_toward(velocity.x, 0,speed)
		velocity.z = move_toward(velocity.z, 0,speed)

for using velocity you can use

		velocity.y = (velocity.x + velocity.z)/2

for using movement you can use

		velocity.y = (abs(direction.x) + abs(direction.y))/2

but this will not let the player jump if they not already running so I recommend adding in an initial jump speed

@pham1506903 hes asking how to make the character jump in 2d is velocity the apt way to accomplish that? i dont use godot but like people’ve suggested i do