how to make enemy AI jump toward player's position

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By amaou310

Hello godot community.
I am currently creating a 2D platformer game and using KinematicBody2D to create enemies that jump towards the player’s position, like a slime. I have managed to create an enemy that jumps towards the player’s position using KinematicBody2D, however, I am not certain whether this is the proper way of doing so.

extends KinematicBody2D

var jump_height = 500
var horizontal_speed = 200
var gravity = 1000

var direction = 1
var velocity = Vector2.ZERO

func _ready():

func _physics_process(delta):
	if velocity.x>0:
	elif velocity.x<0:
	if is_on_wall() or not $Position2D/FloorRay.is_colliding() and is_on_floor():
		direction = direction * -1

	var player_pos = get_node("../Player").get_global_position()
	var self_pos = get_global_position()
	var jump_distance = (player_pos - self_pos).normalized()
	if Input.is_action_just_pressed("jump") and is_on_floor():
		#velocity = jump_distance.normalized()
		velocity.x *= horizontal_speed 
		velocity.y = -jump_height * jump_distance.x
		velocity.y += gravity * delta
		if is_on_floor():
			velocity.x = 0.0
	velocity = move_and_slide(velocity, Vector2.UP)
:bust_in_silhouette: Reply From: exuin

Sorry, why do the enemies jump when the player presses jump?