Getting Sun Position?

Hi, I’m wondering if there’s anyway to get the Sun’s Position in-game in correspondance to the WorldPosition - I’m looking at having an item that’ll shoot into the Direction of the Sun before having an effect.

I know there’s SunDirection, but is there any way to get Sun WorldPosition?

Below is a simple example of what I mean - Snipped from Skyrim: Dawnguard.

5 Likes

Pretty sure it would be hard to get the sun’s position using GeographicLatitude and ClockTime or TimeOfDay, try using an anchored rotating part (positioned either on the player or 0,0,0) connected to one in the sky, then sync it up with the sun in the sky.

This may help

2 Likes

Yes, there is a simple way to figure this out.

(Go under lighting then Data)

You will find “ClockTime” and “GeographicLatitude” You can use both of these values to calculate the positioning of the sun! Your welcome. :slight_smile:

1 Like

I think you’ve tried this already, but have you tried using Lighting:GetSunDirection()? It returns the direction the sun is facing from the origin (0, 0, 0)

4 Likes

Yes, this points to where the Sun is facing as opposed to the actual Suns Position in the Sky.

What formula can I use to convert the Geographic Latitude & Clock Time into WorldPosition / Vector3?

The sun has no actual position, since it’s locked to the skybox. So the direction of the sun is the most valuable information. The sun technically exists at infinity on that directional vector.

If you’re trying to get a part to block the sun, it gets a bit tricky. You can’t throw a part at infinity, because you would never see it. So you’d have to get a bit fancy with your code to figure this out. I don’t know how to do this at the top of my head, but maybe someone else has a solution for it.

1 Like

it’s really simple actually

local part = Instance.new("Part");
local lighting = game:GetService("Lighting");
local distFromCam = 16;
part.Anchored = true;
part.Size = Vector3.new(1,1,1);
part.Parent = workspace.CurrentCamera;
part.CanCollide = false;
game:GetService("RunService").RenderStepped:Connect(function()
	part.Position = workspace.CurrentCamera.CFrame.Position + lighting:GetSunDirection() * distFromCam;
end);
21 Likes

Nice, glad it wasn’t anything too crazy

1 Like

!!

18 Likes

That’s cool. Thank’s for sharing.