Double jump increases exponentially with every jump

Godot 4

Hi, new to Godot, just started messing around with the built in character controller script in 3D. I wanted to add a double jump, but with every double jump it seems to get higher exponentially and I don’t know why. I’ve tried messing with the jump velocity in the double jump, but it never changes.

The code:

extends CharacterBody3D

const SPEED = 5.0
const JUMP_VELOCITY = 4.5

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

var gravity = ProjectSettings.get_setting(“physics/3d/default_gravity”)
var CanDoubleJump: bool = true
var x = 1

func _physics_process(delta):
# Add the gravity.
if not is_on_floor():
velocity.y -= gravity * delta

# Handle jump.
if Input.is_action_just_pressed("ui_accept") and is_on_floor():
	velocity.y = JUMP_VELOCITY
	CanDoubleJump = true

if Input.is_action_just_pressed("ui_accept") and not is_on_floor() and CanDoubleJump == true:
	velocity.y = JUMP_VELOCITY
	CanDoubleJump = false

# Get the input direction and handle the movement/deceleration.
# As good practice, you should replace UI actions with custom gameplay actions.
var input_dir = Input.get_vector("move_left", "move_right", "move_up", "move_down")
var direction = (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 = move_toward(velocity.x, 0, SPEED)
	velocity.z = move_toward(velocity.z, 0, SPEED)

move_and_slide()

I don’t know if this will help but this is from the platformer I have on hold.

This is inside my players script file

extends CharacterBody2D
@export var SPEED = 300
@export var JUMP_VELOCITY = -410
@export var JUMP_COUNT = 0 #Use to count jumps
@export var JUMP_COUNTER = 1 #Feed hard limit based on floor/air. Code is messy but working.
@export var velocityplayer = 1
# 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):
	# Add the gravity.
	if not is_on_floor():
		velocity.y += gravity * _delta
		
	
	# Handle Jumping. Changed code to include JUMP vars and new IF staement for is_on_floor JUMP_COUNT.
	if Input.is_action_just_pressed("space_jump") and JUMP_COUNT < JUMP_COUNTER:
		velocity.y = JUMP_VELOCITY
		JUMP_COUNT += 1
		$Icon/PlayerAni.play("player_jump")
		
		
	if is_on_floor():
			JUMP_COUNT = 0

this is in a power up that has it’s own script.

extends Sprite2D

		#Makes powerjump available per level only!
func _on_area_2d_body_entered(player): #change body to player
	if player:
		player.JUMP_COUNTER = 2        #Allows for triple jump
		player.JUMP_VELOCITY = -460  #Slightly less gravity
		print("power up Jump")
		var tween = create_tween() #Needed for tween creaton
		tween.tween_property(self, "position", position + Vector2(0, -150), 0.3) #Rasies power up based on vector and then speed
		tween.tween_property(self, "modulate:a", 0.0, 0.1) #Fades power up, speed of fade
		tween.tween_callback(self.queue_free)

okay, after some testing I realize the issue seems to be with the velocity. jump count is fine and stuff, but I can’t seem to change the jump velocity on the second jump in the double jump.