Created
August 1, 2017 02:18
-
-
Save lorecrafting/f0b956b2613781d48eacc05a9917e1c0 to your computer and use it in GitHub Desktop.
Unity3d - have object rotate toward target using quaternions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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