robber-and-dobber/Assets/FastIK/Scripts/FastIK/FastIKLook.cs
2021-08-28 14:56:41 +02:00

40 lines
899 B
C#

using UnityEngine;
namespace DitzelGames.FastIK
{
public class FastIKLook : MonoBehaviour
{
/// <summary>
/// Look at target
/// </summary>
public Transform Target;
/// <summary>
/// Initial direction
/// </summary>
protected Vector3 StartDirection;
/// <summary>
/// Initial Rotation
/// </summary>
protected Quaternion StartRotation;
void Awake()
{
if (Target == null)
return;
StartDirection = Target.position - transform.position;
StartRotation = transform.rotation;
}
void Update()
{
if (Target == null)
return;
transform.rotation = Quaternion.FromToRotation(StartDirection, Target.position - transform.position) * StartRotation;
}
}
}