AI scripting Question.

Hi There!
So, I recently started scripting AI and I see to be having a problem…
The AI will start following me, but if I jump it will start flying towards me…
And wont go back onto the ground…
And I can not seem to figure out why?
Here’s the code

if(CanWalk == true)
		{
			spider.position += spider.forward *moveSpeed * Time.deltaTime;
			spider.rotation = Quaternion.Slerp(spider.rotation, Quaternion.LookRotation(Character.position - spider.position), rotationSpeed*Time.deltaTime);

			Debug.Log ("The Spider Is Walking Towards Player");
		}

When you specify spider.rotation you use as reference the Character.position. However this takes the y component of the characters position too, but you don’t want to do that if you want the spider to stay on the ground when you jump. So try this:

float groundLevel; //set this to the y value for your ground level

if(CanWalk == true)
    {
      Vector3 characterHorizontalPosition = new Vector3(Character.position.x, groundLevel, Character.position.z);

      spider.position += spider.forward *moveSpeed * Time.deltaTime;
      spider.rotation = Quaternion.Slerp(spider.rotation, Quaternion.LookRotation(characterHorizontalPosition - spider.position), rotationSpeed*Time.deltaTime);
 
      Debug.Log ("The Spider Is Walking Towards Player");
}

You are rotating the spider to constantly face you and move forward. What happens is that when you jump, the spider looks slightly up into the air (towards you), and the forward vector that you are moving it by is now also facing into the air, so when you move him forward, he leaves the ground.
What you should do is add a rigidbody and a collider to make him stick to the ground, and also rotate him to face you only on the Y axis, to prevent him from looking up or down and only follow you on that axis.