Quantcast
Channel: Latest Questions by Napoleonite
Viewing all articles
Browse latest Browse all 12

[2D] Get 0-359 compass angle player object

$
0
0
The closest I could find on the answerhub was: float AngleBetweenMouseAndPlayer() { Vector3 v3Pos; float fAngle; //Convert the player to Screen coordinates v3Pos = Camera.main.WorldToScreenPoint(transform.position); v3Pos = Input.mousePosition - v3Pos; fAngle = Mathf.Atan2(v3Pos.y, v3Pos.x) * Mathf.Rad2Deg; if (fAngle < 0.0f) fAngle += 360.0f; return fAngle - 90f; } I can rework this code to work for 2 object <--> player. However, in this code the north returns 0, the east -90, the south 180 (the only correct one), and the west 90 degrees... I need a function that returns me (for 2D space): 0 if the other object is exactly north of the player. 90 if the other object is exactly east of the player. 180 if the other object is exactly south of the player. 270 if the other object is exactly west of the player. And of course all values in between, but no negative values.

Viewing all articles
Browse latest Browse all 12

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>