Skip to content

Instantly share code, notes, and snippets.

@rioter00
Created April 17, 2020 18:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rioter00/6de766bfb653771a57f75a2fbd768a6e to your computer and use it in GitHub Desktop.
Save rioter00/6de766bfb653771a57f75a2fbd768a6e to your computer and use it in GitHub Desktop.
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