I have this zombie wandering around between random waypoints, now the problem is that with transform.LookAt(), he instantly looks to that target. Is there a way to just rotate slowly to the target, to make it more realistic?
Lots of thanks
This question has been answered a bunch of times, but a quick search did not produce a clean answer, so:
var q = Quaternion.LookRotation(target.position - transform.position);
transform.rotation = Quaternion.RotateTowards(transform.rotation, q, speed * Time.deltaTime);
‘speed’ is a variable defined at the top of the file. You can substitute Lerp() for RotateTowards() (and reset speed as appropriate) if you want an eased movement.
First, use Quaternion.LookRotation to get the target direction that you want the Zombie to look at. Then lerp the quaternion of the Zombie from it’s current quaternion to the target quaternion found before.
How do you detect when the angles are sufficiently close so that you can, say exit the coroutine if that’s where you put this code? For single axis there’s Mathf.DeltaAngle. How would you compare quaternions?