I have a simple question on usage of math.Atan2 function with Unity in a 3D environment.
I found this code on Unity's documentation for Math.Atan2. I changed it a bit to fit my needs.
Vector3 waypoint = Random.insideUnitSphere + new Vector3(Random.Range(minX+1.5f, maxX-1.5f),prevPosY,Random.Range(minZ + 1.5f,maxZ - 1.5f)); //waypoints are generated based on random unit sphere + ( bounds of the plane they are on ) Vector3 relative = transform.InverseTransformPoint (waypoint); float angle = Mathf.Atan2 (relative.x, relative.z) * Mathf.Rad2Deg;
I know how it works in a normal 2D coordinate system, however when switching to a 3D coordinate system, if I would want to move my character on the x-z plane, then how does this actually work mathematically?
I am assuming that it would be the angle between z and x axis? so in a mathematical equation would it be, angle = Atan2(z/x) or Atan2(x/z)? Would both of them work?