Get Skybox Position from World Position

Similar to env_headcrabcanister, is there a way to find where a position in the regular map would translate to in the skybox, and vice versa?

As well, what is the exact factor by which entities in the skybox are enlarged by when viewing them from inside the map?


Bump, still curious, had some really fun ideas in mind if this is possible!

the factor you can set in hammer using the sky_camera entity.
to find the most top part of your map, which is mostly the skybox, just make a trace / ranger upwards and add the Z to your position?

The gamemode I work on, scan the given map-size using tracers. It works 70% of the time.

Wait to run the code after the entities have been placed: GM:InitPostEntity()

  • Use tracers to get the height of the map … then run a trace at the height (So there aren’t any obstacles) to get the weight and depth.
  • Find the sky_camara (it’s around the center of the skybox).
  • Use tracers at sky_camara to get the height, weight and depth.
  • Hookup GM:SetupSkyboxFog(), it’s called with the Skybox scale:
    SkyboxScale = 0
    SkyboxScale = SC

You should now have:

  • MapSize
  • SkyboxSize/pos
  • SkyboxScale


  • Might be incorrect if the map have big buildings or any sort of obstacles in the skybox.
  • You can’t compare the skybox’s position with the maps.

Or you can poke in the Garrysmod-github for a function that returns the variables. cough cough Robotboy655

That’s a great idea. I suppose what I could also do is, with some other math concerning the skybox scale, find the offset of the entity I’m focusing on from Vector(0,0,0), and re-create it at the same offset, but with sky_camera as its origin.

After reading about sky_camara … it dos mark the origin of the map inside the skybox.
I think that might mean that sky_camara’s position marks Vector(0,0,0) in the skybox.

You can test it if you need a specific position. :stuck_out_tongue:

Yeah, sky_camera is what you want. The 3rd skybox scale is also defined in it. I am not sure if it spawns in the map though, or if it is removed on map compile and its data is put somewhere else.

Nope, just tried it

for k,v in pairs(ents.FindByClass("sky_camera")) do

Found the camera on gm_construct

It spawns on the serverside … however I’m unable to retrieve details like skybox-scale … ect.

I’m using the entity’s :GetSaveTable().scale to retrieve it scale

Here you guys go, this seems to work just fine now. I whipped up a function to translate a position to the skybox.

function util.WorldToSkybox(pos)
    local campos
    local skyscale = 1
    for k,v in pairs(ents.FindByClass("sky_camera")) do
        campos = v:GetPos()
        skyscale = v:GetSaveTable().scale
    local offset = pos/skyscale
    return campos+offset


Well you know, I figure, might as well have a way to convert a skybox position into the world, so here you go, too.

function util.SkyboxToWorld(pos)
    local skyscale = 1
    local campos
    for k,v in pairs(ents.FindByClass("sky_camera")) do
        skyscale = v:GetSaveTable().scale
        campos = v:GetPos()
    local offset = (pos-campos)*skyscale
    return Vector(0,0,0)+offset

Maybe these could be made standard functions? They seem useful enough.