Trying to have enemy copy player on a delayed various timing in mario run like game

Godot Version

Godot 4.2

Question

So I am making a 2d autorunner platformer similar to super mario run, vector, and geometry dash
Its more of a goofy game though.

So the player is a rich guy running from the IRS and theres going to be those two in the level. I want to try and make it so that as you, the player, do moves (jump, wall jump, etc.) the enemy will do them after you at the same place you did.

I cannot sync the enemy’s movement to the players in a way that allows it to also do an action like jump in the correct spot. it would either jump too early when the player does it or not jump at all.

Heres the player code

extends CharacterBody2D

@export var SPEED: float = 350.0
var JUMP_VELOCITY: float = -500.0
@export var gravity: float = 1000
var wall_jump_count: int = -1

func _physics_process(delta):
handle_physics(delta)

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

# do da jump.
if Input.is_action_just_pressed("jump") and is_on_floor():
	velocity.y = JUMP_VELOCITY

if Input.is_action_just_released("jump"):
	velocity.y *= 0.4

if Input.is_action_just_pressed("ZOOM"):
	SPEED += 1

# do da speed
if wall_jump_count == 1:
	velocity.x = -SPEED
else:
	velocity.x = SPEED

if Input.is_action_just_pressed("jump") and is_on_wall():
	velocity.y = JUMP_VELOCITY
	velocity.x = wall_jump_count * SPEED
	wall_jump_count *= -1

move_and_slide()

Also sorry for formatting. my first time using the forum

If you want to make a runner game where an enemy is chasing the player, I wonder why you would want the enemy to copy the player. If you make the enemy copy the player, the enemy will also mess up when the player does.

Instead you could just give the enemy his own behaviour, he will jump (or perform any other action) when he needs to. This can be achieved by placing Area2Ds at places where you want the enemy to jump, and then connecting the body_entered signal to the enemy’s jump function

I have no idea why I didn’t think of this either to be honest lol thanks!

Originally my thought was the player loses by either falling off the map or getting caught by the enemy or falling in the obstacle and the only way you get caught by enemy is if you get stuck on like an obstacle or a wall jump somewhere so the enemy will catch up to the player, however I didn’t think of the possibility of a player just circling the enemy and never being caught while also not proceeding in the level
I didn’t even think of that that’s so crazy