Skip to content

Instantly share code, notes, and snippets.

@lorecrafting
Created August 1, 2017 02:18
Show Gist options
  • Save lorecrafting/f0b956b2613781d48eacc05a9917e1c0 to your computer and use it in GitHub Desktop.
Save lorecrafting/f0b956b2613781d48eacc05a9917e1c0 to your computer and use it in GitHub Desktop.
Unity3d - have object rotate toward target using quaternions
using UnityEngine;
using System.Collections;
public class LookAtScript : MonoBehaviour {
public Transform target;
void Update() {
Vector3 relativePos = target.position - transform.position;
transform.rotation = Quaternion.LookRotation(relativePos);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment