// カメラから部隊までのベクトル Vector3 cameraToPos = unitPos - thisGame.mainMap.GetCameraPosition(); // カメラから部隊までの距離 float length = (cameraToPos).Length(); // スケールレート float scaleRate1 = 100 / length; // ネームプレートを配置すべき3次元座標の方向ベクトルを求める // (カメラから部隊までのベクトルに垂直なベクトルを求める) // XY平面上の元斜辺の長さ double sqrtXY = Math.Sqrt(cameraToPos.X * cameraToPos.X + cameraToPos.Y * cameraToPos.Y); // XZ平面上の元斜辺の長さ double sqrtXZ = Math.Sqrt(cameraToPos.X * cameraToPos.X + cameraToPos.Z * cameraToPos.Z); // XY平面上の元斜辺の角度 double atan2XY = Math.Atan2(cameraToPos.Y, cameraToPos.X); // XZ平面上の元斜辺の角度 double atan2XZ = Math.Atan2(cameraToPos.Z, cameraToPos.X); // XZ平面上の新斜辺の長さ double newXZ = sqrtXY * Math.Sin(atan2XY); // ネームプレートを配置すべき3次元座標の方向ベクトル Vector3 newVec = new Vector3( (float)(-newXZ * Math.Cos(atan2XZ)), (float)sqrtXZ, (float)(-newXZ * Math.Sin(atan2XZ))); Console.WriteLine("cameraToPos = " + cameraToPos.ToString() + " newVec = " + newVec.ToString()); Vector3 newPos = Vector3.Normalize(newVec) * scaleRate1 + unitPos; Console.WriteLine("newPos = " + newPos.ToString());