Prevent AI from ascending on Y-axis?

I am using a Grid Graph in Unity 2D and have an enemy AI that has the AIPath script and also the patrol script so he can patrol an area. I have modifed the patrol script so he can also target an player when the player is in radius. However when the player jumps on the enemy(head) then the enemy will ascend upwards trying to catch up to him, so how can I prevent the enemy ai from ascending upwards on the Y-axis while still keeping the ability of falling downwards on the Y-axis?

A fragment of the modifed patrol script:

[SerializeField] private Transform target;
public bool targetThePlayer = false;
private void Update()
if (!targetThePlayer) //not targeting the target, patroling…
if (targets.Length == 0) return;

			bool search = false;

			// Note: using reachedEndOfPath and pathPending instead of reachedDestination here because
			// if the destination cannot be reached by the agent, we don't want it to get stuck, we just want it to get as close as possible and then move on.
			if (ai.reachedEndOfPath && !ai.pathPending && float.IsPositiveInfinity(switchTime))
				switchTime = Time.time + delay;

			if (Time.time >= switchTime)
				index = index + 1;
				search = true;
				switchTime = float.PositiveInfinity;

			index = index % targets.Length;
			ai.destination = targets[index].position;

			if (search) ai.SearchPath();
		else //targeting the target
			ai.destination = target.position;


That sounds like they are including each other in their ground raycast layer masks. Make sure they are excluded so that their raycasts dont hit each other.