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);
}