Skip to content

Instantly share code, notes, and snippets.

@andresfelipemendez
Created July 7, 2015 01:28
Show Gist options
  • Save andresfelipemendez/058303005f84752d1eda to your computer and use it in GitHub Desktop.
Save andresfelipemendez/058303005f84752d1eda to your computer and use it in GitHub Desktop.
Rotation, the object at the center will rotate towards the target
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