// direction of aim our object starts with vector $a = <<0, 0, 1>>; // vector from our object to the camera vector $b = unit(<>); // find the angle between vectors, convert to degrees if (camera1.translateX > 0) pCube1.rotateY = acos($a.x*$b.x + $a.z*$b.z) * 57.2957795; else pCube1.rotateY = acos($a.x*$b.x + $a.z*$b.z) * -57.2957795;