Skip to content

Instantly share code, notes, and snippets.

@rastating
Last active August 29, 2015 13:55
Show Gist options
  • Save rastating/8699273 to your computer and use it in GitHub Desktop.
Save rastating/8699273 to your computer and use it in GitHub Desktop.
using UnityEngine;
using System.Collections;
public class AimAssist : MonoBehaviour {
void Start () {
}
void Update () {
Vector3 mouse_pos = Input.mousePosition;
Vector3 player_pos = Camera.main.WorldToScreenPoint(this.transform.position);
mouse_pos.x = mouse_pos.x - player_pos.x;
mouse_pos.y = mouse_pos.y - player_pos.y;
float angle = Mathf.Atan2 (mouse_pos.y, mouse_pos.x) * Mathf.Rad2Deg;
this.transform.rotation = Quaternion.Euler (new Vector3(0, 0, angle));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment