Another way to follow an object?

Currently I am using

if ( Vector3.Distance( leader.position, transform.position ) >= distance) {
	controller.SimpleMove(forward * speed );

But I am curious as to another way to get a npc to follow the ‘leader’. This is fine in theory, but the npc’s z points towards the leader unrealisticly. Is there a way to get the npc to face the player while keeping its z normal?

Right now I am restricting its z bu using

transform.rotation.z = 0;

I don’t want to have such a restriction on it though. In the future I want to add functions to allow the npc to rotate to the ground beneath it, and restrictions like that will be a huge problem. I basically need a new way to get it to follow something more naturally.

Thanks for any help

What I have done is the past is create a Quaternion that points the character in the right direction, then add the other Quaternion that defines the slope.

Quaternions are actually really simple to use. Basically you use something like Quaternion.LookRotation to make one, then you make another, then just use the * operator to add them.

Quaternion.LookRotation(transform.forward, Vector3.up) * Quaternion.RotateTowards(something)

The docs are pretty good for this.

function Update () {

transform.rotation.z = 0;

var hit : RaycastHit;
var castPos = Vector3(transform.position.x,transform.position.y-.25,transform.position.z);
if (Physics.Raycast (castPos, -transform.up, hit)) {
	transform.rotation.x = Quaternion.FromToRotation (Vector3.up, hit.normal).x;

This makes the character extremely buggy and trippy. I think something is screwy in its update function?