problem with ai

hi i am making a game and i am using this code to enemy follow player

transform.Translate(Vector3.forward * moveSpeed * Time.deltaTime);

the problem is my game is on a terrain and has some Heightes now when the enemey is following me he is flying somehow !
now i want to know how can i fix this!
and a easy way is better!

I’m guessing he just collides with the terrain and just stays at the height the terrain last pushed him up to. If your bad guy has to search for the player, use navmesh.
If he has to just run forward and nothing more, use physics to move the enemy instead and he’ll fall and rise with the terrain.

Use a rigidbody, colliders and then use the AddForce method instead. The links below have all the information you need about rigibodies, colliders, etc.

You can use Terrain.SampleHeight() to set the height of your follower after you have moved him:

  transform.Translate(Vector3.forward * moveSpeed * Time.deltaTime);
  transform.position.y = Terrain.activeTerrain.SampleHeight(transform.position) + halfHeight;

‘halfHeight’ is the distance between the bottom of your follower and the pivot point. If the pivot point is on the bottom of the follower (a common practice for this kind of game), then you can omit 'halfHeight;