physics problem with object playing

I made a object move towards my player when he came closer to it but it works fine but it also fly in air when moving towards my player . I think it happens because I created a empty object and make it parent object and made this moving object as child object . I add this empty object because for animation but what to do in this case?

Is it in the air all the time or just as it gets closer to the player it gradually goes up in the air?

well the script should be it should move towards the player when he gets closer . so when it started moving towards player it goes in air

Please post your enemy script, remember to tag it as code so it displays correctly.

Out of curiosity, have you done the tutorials? They have stuff like this

here is the script
```csharp
__using UnityEngine;
using System.Collections;

public class Enemyai : MonoBehaviour {
public Transform player;
float distancefrom_player;
public float look_range = 20.0f;
public float agro_range= 10.0f;
public float move_speed= 5.0f;
public float damping = 6.0f;
// Use this for initialization
void Start () {

}

// Update is called once per frame
void Update ()
{
    distancefrom_player = Vector3.Distance (player.position, transform.position);
   
    if (distancefrom_player < look_range )
    {
        transform.LookAt(player);
    }
   
    if (distancefrom_player < agro_range)
       
    {
        attack();
    }
}

void lookAt()
{
    Quaternion rotation = Quaternion.LookRotation (player.position - transform.position);
    transform.rotation = Quaternion.Slerp (transform.rotation, rotation, Time.deltaTime * damping);
}

void attack()
{
    transform.Translate (Vector3.forward * move_speed * Time.deltaTime);
}

}__
```

and also created new script but still the object is in air but in these new script it is little better cause he is almost on ground but not touching the floor here is new script

using UnityEngine;
using System.Collections;

public class AdvancedAi : MonoBehaviour
{
    float distance;
   
    public float lookAtDistance, chaseRange, attackRange, moveSpeed, damping, gravity, attackRepeatTime;
    public Transform target;
    public CharacterController controller;
   
    private Vector3 moveDirection = Vector3.zero;
    private float attackTime;
   
    //TODO: add in a function to find controller and to locate and assign the player as the target
   
    void Start()
    {
        attackTime = Time.time;
    }
   
    void Update()
    {
        distance = Vector3.Distance(target.position, transform.position);
       
        if(distance < lookAtDistance)
        {
            LookAt();
        }
       
        if(distance > lookAtDistance)
        {
            GetComponent<Renderer>().material.color = Color.green;
        }
       
        if (distance < attackRange)
        {
            AttackPlayer();
        }
       
        else if (distance < chaseRange)
        {
            ChasePlayer();
        }
    }
   
    void LookAt()
    {
        GetComponent<Renderer>().material.color = Color.yellow;
        Quaternion rotation = Quaternion.LookRotation(target.position - transform.position);
        transform.rotation = Quaternion.Slerp(transform.rotation, rotation, Time.deltaTime * damping);
    }
   
    void ChasePlayer()
    {
        GetComponent<Renderer>().material.color = Color.red;
       
        moveDirection = transform.forward;
        moveDirection *= moveSpeed;
       
        moveDirection.y -= gravity * Time.deltaTime; // doesn't seem to work right :(
        controller.Move(moveDirection * Time.deltaTime);
    }
   
    void AttackPlayer()
    {
        //TODO: Need Attack Animations
        if (Time.time > attackTime)
        {
            Debug.Log("Attack");
            attackTime = Time.time + attackRepeatTime;
        }
    }
   
    void ApplyDamage()
    {
        chaseRange += 30;
        moveSpeed += 2;
        lookAtDistance += 40;
    }
}

I don’t think you should be using the character controller for your enemy but I could be wrong (I only ever use it for the player character). For the first script, did the enemy have a rigid body because it looks like there is no gravity? & did you zoom in on the enemy in the edit window & watch what was happening as it moved? It could just be that the collider at the base of it extends below your character & it is just pushing up until it is on top of the floor.

Also, with the 2nd one, your move speed is increasing with every call of ApplyDamage so the enemy will keep getting faster & faster. Is this what you wanted? All those values are incrementally getting higher & higher.

but the tutor uses character controller and also I disable 1st script because 2nd is better

is there a rigidbody on the enemy? my basic understanding of character controller is you shouldn’t have a rigidbody on it as it can behave weirdly.

there is no rigid body on the object . it just has skin mesh renderer character controller enemys health script and enemy ai script

Ok, I have no idea. I’ve never had this problem (ive also never used player controller for enemies so couldn’t help anymore anyway)