I have something an old project of mine, where the enemy was facing the player and later chased him. Here's what I used for the enemy to smoothly turn at the target and face him:
var target : Transform;
var damp = 6.0;
function lookAtTarget() {
var rotation = Quaternion.LookRotation(target.position - transform.position);
transform.rotation = Quaternion.Slerp(transform.rotation, rotation, Time.deltaTime * damp); //turn smoothly
}
It's JS though. Hope it helps.
↧