NPC Enemy over Terrain

Hello. I want to create some enemys who can walk over a terrain with mountains.

NPCs has a random movement in x and z axis. But the y axis is the problem.
They are humans like me (the player character), and they need how to going over the terrain different y values.

I tried yo use a character motor and a character movement, and a rigidbody with a capsule collider. Two diferent ways but i can’t do usefull the movement.

I programmed the NPC for follow me in (x,z) plane. This is the concept code (for the NPC):

var posme: Transform //// me
var vectorvel;
var velfactor : float;
function Update()
{
   vectorvel = posme.position - transform.position;
   rigidbody.velocity.x = vectorvel.x * velfactor;
   rigidbody.velocity.z = vectorvel.z * velfactor;
}

I want that the following works only in x and z axis. The y position of the NPC has to be the terrain y value in this (x,z) position.

Have I to use raycasting to get the y value of the terrain? Can the NPC be some intelligent and know the y value only being a rigidbody with a collider?

I tried this but the movement fails. It seems that there are a lot of friction between the NPC and the terrain.

Thanks.

If you use a CharacterController and CharacterController.Move(directionVector), it will handle the majority of the y-axis movement. After this it is up to you to apply a downward force (gravity) when it is not touching the ground.

Good luck!

-JFFM

Thanks JFFM !!, I will try it this night (day in your case) xD

Good. It works! thanks a lot. my enemys are moving nicely