# Usage of math.Atan2 in a 3D coordinate system with Unity

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?

Beware of the argument order here. Here is what atan2 will give you:
• atan2(x,z) is the angle between the (x,0,z) vector and the +Z axis in the Z-X plane.
• atan2(z,x) is the angle between the (x,0,z) vector and the +X axis in the X-Z plane.