I want to move to be modular but I also want to apply gravity to the entitys that has move loaded when they are in a 2dplane:

extends Node2D
# Called when the node enters the scene tree for the first time.
func execute(s, dir = []):
	s.velocity = Vector2(0,0)
	if dir.has("up") && GameManager.current_plane != "2D":
		s.velocity.y -= 1
	if dir.has("down") && GameManager.current_plane != "2D":
		s.velocity.y += 1
	if dir.has("left"):
		s.velocity.x -= 1
	if dir.has("right"):
		s.velocity.x += 1
	
	if dir.has("jump") && GameManager.current_plane == "2D":
		s.velocity.y -= 1
	

	if dir.size():
		
		s.velocity = s.velocity * s.current_speed
		s.velocity.normalized()
		
		s.move_and_slide()





entity:
extends CharacterBody2D
class_name Entity

#var death_scene =
var death_config = {}
var direction : Vector2 = Vector2()

var max_health = 40
var current_health : int = 40
var health_regen : int = 1
var armor : int = 0

var max_mana : int = 100
var current_mana : int = 100
var mana_regen : int = 1

var max_speed : float = 100
var current_speed : float = 100
var acceleration : float = 4

var agility : int = 1

var global_cooldown = 30
var is_busy : bool = false
var last_ability : int = 0

var is_player : bool = false
var is_aliv : bool = true
var has_gravity = true

var gravity: float = 98.0 # Adjust the gravity force as needed

func get_State():
	return {
		"direction": direction,
		"max_health": max_health,
		"current_health": current_health,
		"health_regen": health_regen,
		"armor": armor,
		"max_mana": max_mana,
		"current_mana": current_mana,
		"mana_regen": mana_regen,
		"max_speed": max_speed,
		"current_speed": current_speed,
		"acceleration": acceleration,
		"agility": agility,
		"global_cooldown": global_cooldown,
		"is_busy": is_busy,
		"last_ability": last_ability,
		"is_player": is_player
	}
func _ready():
	add_to_group("entity")
	
func get_enemies():
	var enemy_group = get_enemy_group()
	var enemies = get_tree().get_nodes_in_group(enemy_group)
	return enemies

func get_enemy_group():
	var enemy_group = "friend"
	if is_player: enemy_group = "foe"
	return enemy_group

func find_nearest_enemy():
	return get_enemies()[0]
	
func get_aim_position():
	if is_player: return get_global_mouse_position()
	else: return find_nearest_enemy().global_position
	
func regen_health():
	if (current_health < max_health):
		if((health_regen + current_health) > max_health):
			current_health = max_health
		else: current_health += health_regen
		if is_player:EventManager.regen_health_ui.emit(current_health)
	
func regen_mana():
	if (current_mana < max_health):
		if((mana_regen + current_mana) > max_mana):
			current_mana = max_mana
		else: current_mana += mana_regen

func modify_mana(amount):
	var new_mana = current_mana + amount
	if(new_mana < 0): current_mana = 0
	if(new_mana > max_mana): current_mana = max_mana
	else: current_mana += amount

func can_cast_ability(mana_cost):
	if(current_mana - mana_cost) >= 0:
		modify_mana(-mana_cost)
		return true
	else:
		print("not enough mana!")
		return false

func apply_damage(amount):
	if is_player: 
		EventManager.frame_freeze.emit()
		EventManager.update_health_ui.emit(amount)
	if(armor > 0): amount = amount *((100-armor)*0.01)
	if(current_health > amount): current_health -= amount
	else:
		current_health = 0
		if(!is_player):
			#var loot = death_scene.instantiate()
			#loot.position = self.global_position
			#loot.config = death_config
			#get_nod("/root").add_child(loot)
			self.queue_free()
		else:
			die()

func _physics_process(delta):
	last_ability += 1
	if has_gravity:
		apply_gravity(delta)
	if ((GameManager.count % 60) == 0):
		regen_health()
		regen_mana()
	
func load_ability(ability_name):
	var scene = load("res://Scenes/abilities/" + ability_name + "/" + ability_name + ".tscn")
	var sceneNode = scene.instantiate()
	add_child(sceneNode)
	return sceneNode
	
func die():
	AudioManager.play_sound(AudioManager.DEATH)
	EventManager.player_died.emit()
	queue_free()
	
func apply_gravity(delta):
	# Apply gravity to the player’s velocity
	if GameManager.current_plane == "2D":
		# Apply gravity to the player’s velocity
		velocity.y += gravity * delta
		
		# Move the player and process collisions
		if self is CharacterBody2D:
			# Assuming you have a floor_normal set up correctly and a max_slides value
			move_and_slide()
			# You can reset y velocity if on the floor
			if is_on_floor():
				velocity.y = 0
				velocity.x = 0
		else:
			# If the entity is not a KinematicBody2D, you’ll need another way to apply velocity.
			# It will depend on how your Entity class handles physics and movement.
			pass