Created
April 17, 2020 18:40
-
-
Save rioter00/6de766bfb653771a57f75a2fbd768a6e to your computer and use it in GitHub Desktop.
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 System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
public class MouseLookAt : MonoBehaviour | |
{ | |
// if your character is rotating but off a fixed angle, adjust this value, likely will be 90 or -90 (degrees) | |
[SerializeField] int angleOffset; | |
// Update is called once per frame | |
void Update() | |
{ | |
var dir = Input.mousePosition - Camera.main.WorldToScreenPoint(transform.position); | |
var angle = Mathf.Atan2(dir.y, dir.x) * Mathf.Rad2Deg + angleOffset; | |
transform.rotation = Quaternion.AngleAxis(angle, Vector3.forward); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment