Created
July 7, 2015 01:28
-
-
Save andresfelipemendez/058303005f84752d1eda to your computer and use it in GitHub Desktop.
Rotation, the object at the center will rotate towards the target
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
Vector3 pos = Camera.main.ScreenToWorldPoint (new Vector3 (${Target}.position.x, ${Target}.position.y, 5)); | |
float angle = Mathf.Atan((pos.y - ${Center}.position.y) / (pos.x - ${Center}.position.x)) * Mathf.Rad2Deg; | |
if(pos.x < transform.position.x){ angle += 180; } // avoid 'flipping' the rotation | |
${Center}.transform.rotation = Quaternion.Euler(0, 0, angle); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment