Does anyone know how I would do this, or any resources out there I can learn from on how to slowly rotate a model from one point to another? The idea is to move a model from waypoint to waypoint and to slowly rotate the model from the current waypoint to the next waypoint. I have the movement done but LookAt() instantly rotates and it looks horrible. I tried below, but it's saying UnityEngine.Component.transform is read only.
Iam using this for my turret! Code (csharp): // Put the barrel on the top of the model as this look at rotation is restricted to z axis ! //Remove ( , Vector3.forward ) at the end so will you get an all axis smooth look at rotation. // Also remove these ( newRotation.x = 0.0; newRotation.y = 0.0; ) // Get the target rotation var newRotation = Quaternion.LookRotation(transform.position - target.transform.position, Vector3.forward); newRotation.x = 0.0; newRotation.y = 0.0; // Smoothly rotate towards the target . transform.rotation = Quaternion.Slerp(transform.rotation, newRotation, speed*Time.deltaTime);
Cool, I have the following and it works perfectly. Code (csharp): // rotate towards the currentWaypoint var targetPoint = currentWaypoint.transform.position; var targetRotation = Quaternion.LookRotation(targetPoint - transform.position, Vector3.up); transform.localEulerAngles.x = 0; transform.rotation = Quaternion.Slerp(transform.rotation, targetRotation, Time.deltaTime * currentWaypoint.rotationSpeed);