Hello,
I did some research on the topic and I couldn’t understand any answers so I decided to ask here. I would like my character to face the object, here is that part of the script:
function lookAt ()
{
var rotation = Quaternion.LookRotation(Target.position - transform.position);
transform.rotation = Quaternion.Slerp(transform.rotation, rotation, Time.deltaTime * Damping);
}
The problem comes when “Target” gets to close to this object and it leans slightly back to deal with the Y axis, I thought if it would only face the objects X and Z axis it might fix this.
Any help is appreciated.
Thanks.
function lookAt() {
// Store the other object's position in a temporary variable
var temp = Target.position;
// Deflate it's x and z coordinate
temp.x = temp.z = uint.MinValue;
var lookRotation = Quaternion.LookRotation (temp);
transform.rotation = Quaternion.Slerp (transform.rotation, lookRotation, Damping * Time.deltaTime);
}