【CSOL】上帝視角跟隨UI
? ? -- 將3D坐標(biāo)轉(zhuǎn)換為UI坐標(biāo)
? ? function projectToUI(x, y, z, cameraX, cameraY, cameraZ, screenWidth, screenHeight)
? ? ? ? local dx = x - cameraX+3
? ? ? ? local dy = y - cameraY-3
? ? ? ? local dz = z - cameraZ
? ? ? ??
? ? ? ? local scale = screenHeight / (dz + cameraZ)
? ? ? ??
? ? ? ? local screenY = screenWidth / 2 - dx * scale
? ? ? ? local screenX = screenHeight / 2 - dy * scale
? ? ? ??
? ? ? ? return screenX, screenY
? ? end
--用法(update)? ?1280/960是玩家的分辨率
chestUIX1, chestUIY1 = projectToUI(monster1.position.x, monster1.position.y, 22, player.position.x, player.position.y, player.position.z, 1280, 960)
標(biāo)簽: