Quaternion.LookRotation wiggles around

In the game there is this town that has creatures living in it. I’ve made spheres (that will be invisible for the player) on the streets and the creatures walk from one sphere to another. When a creature hits sheres collider that is been given before, the sphere gives the creature randomly new spheres Transform position to go to. And it goes on like this.

I’ve used Quaternion.LookRotation to slowly turn to the next destination.

The problem is that although it works most of the time, it sometimes starts to wiggle left and right. I made tiny video about it.

Here’s the code I’ve used. Well the main parts anyway. All help is welcome.

var endMarker : Transform;

function Update () {  

var newRotation = Quaternion.LookRotation(endMarker.position - transform.position, Vector3.forward);
newRotation.x = 0.0;
newRotation.z = 0.0;
transform.rotation = Quaternion.Slerp(transform.rotation, newRotation, Time.deltaTime * turningspeed);	

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

}

Hmm kind of interesting I see.

All I can think of is maybe try adding an “if” condition to eliminate Vector3.zero like this:

if ( _direction != Vector3.zero) {
       	_lookRotation = Quaternion.LookRotation(_direction);
}

Except substitute your variables in there. I know it’s not exactly the same but maybe you can figure it out. The goal would be to not rotate if the direction you input into your quaternion is Vector3.zero. That might help stabilize it.

Just a thought, it might not work, but who knows. Good luck.