Normal Matching problem - between to angles.

Hi i am having some problems when i try to match my player to the normal of the ground.

It works nice some times but it can be very flickery in parts and in accurate when a hill is finished,

Say the hill is at an angle once finced walking up the player will be still matching the angle, other problems can leave the player rotated in the wrong way and look very bad.

if (Physics.Raycast(transform.position, -Vector3.up, hit, rayDistance, layerMask)) 
{
	transform.rotation = Quaternion.FromToRotation (Vector3.up, hit.normal)  * Quaternion.LookRotation(xzMove);
}

Its pretty good if your moving at a good speed like running around but if you step slowly it becomes very noticable.

Would this help?

Quaternion desiredRotation;

void Update()
{


if (Physics.Raycast(transform.position, -Vector3.up, hit, rayDistance, layerMask)) 
{
    desiredRotation = Quaternion.FromToRotation (Vector3.up, hit.normal)  * Quaternion.LookRotation(xzMove);
}

this.rotation = Quaternion.Lerp(this.rotation, desiredRotation * Time.deltaTime)

}

Thanks is there a way to make it so that the xzMove rotation is not effected by the lerp? As I don’t want to effect that rotation with time.

Thanks

if (Physics.Raycast(transform.position, -Vector3.up, hit, rayDistance, layerMask))
{
desiredRotation = Quaternion.FromToRotation (Vector3.up, hit.normal);
}

this.rotation = Quaternion.Lerp(this.rotation, desiredRotation * Time.deltaTime)* Quaternion.LookRotation(xzMove);