Unable to keep the xz rotation of avatar while playing anim in animator

I m simply playing an animation that makes my player to run forward. Everything is nice and the player has a capsule collider with a character controller. The preview is working fine. I have also a terrain with raised paintings that make the terrain more complex. Now, when i play and watch the player is roaming on the terrain it looses the xz - rotation somehow. It is doing many fantastic things just like rolling on the ground, but the same anim is still running. How can i fix or freeze the rotation preventing from being distracted affected in the scene.
thx,

i solved it by my own. As the players were positioned on the ground of the terrain the y - position is zero. So i redefined the calculated new direction for its y component also to zero. It s looking fine for this time, as much i can now make out of the result.

Vector3 newDirection = g[id].transform.position - transform.position;
newDirection.y = 0;

Vector3 v3 = Vector3.RotateTowards(transform.forward,newDirection ,5.0f,0.0f);
transform.rotation = Quaternion.LookRotation(newDirection);