How can i detect if player is under the sky?

What I mean is how could i check if the player is directly under the sky (like if the sunlight was directly hitting him), and also check when the player is under a ceiling (and not under the map’s sky)

I tried using the “IsSkyboxVisibleFromPoint”

hook.Add("Think","checkIfOutside", function(plyPos)
if util.IsSkyboxVisibleFromPoint(LocalPlayer():GetPos()) == true then
	print("I'm under the sky")
if util.IsSkyboxVisibleFromPoint(LocalPlayer():GetPos()) == false then
	print("I'm not under the sky")

But It kept spamming me the message of “I’m under the sky”, inside the buildings, and every place in the map except, for some reason, the gm_construct’s white room (which is full bright) and instead it printed the “Im not under the sky” message

In the wiki it says that “This will always return true in fullbright maps” (I’m in GM_Construct checking this) so even if it worked on other maps, it’s not reliable.

Or maybe you could detect the light level so that when it is sky brightness it returns true and when it’s darker it returns false. But still, I need to somehow detect that the player is directly under the skylight, because if I’m using atmos (which I am), or any other daytime/nighttime addon, it will think it’s not under the sky at nighttime. Help is really appreciated, and if there was an obvious solution to this, excuse me, I’m new at GLUA.

You can create a trace on each player and check if it hits the skybox.



You could use and check Trace.HitSky.

TraceHull doesn’t work well in clientside


util.TraceLine be better?

Since it uses physic calculations inside engine, the difference it’s not that big

Forgot to answer.

Thanks alot to everyone for answering! It worked perfectly with the trace and I can now do what I wanted :slight_smile: