Last active
August 29, 2015 13:55
-
-
Save rastating/8699273 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 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