# Sun Physics Day/Night

This topic is 565 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hello,

I have a isometric 2D game and wanted to add a sun and cast some shadows.

I'm rotating the "Sun" around the viewport the Suns direction is always the center of the viewport.

I can calculate the Position and the Direction which is working fine.

My question is does the shadow rotate around the object during day? or just change it's scale? or both?

if it roates does it rotate around it for 360Â° during the day?

Edited by Stealth Kill

##### Share on other sites
My question is does the shadow rotate around the object during day? or just change it's scale? or both?

Depends on what you want.

It is perhaps easiest to consider your "earth" flat, and the sun floating around that flat disc in 3D. (We discovered long ago that it's easier to compute orbits of other planetary rocks in the solar system when you assume the Sun is the center point, but you don't have that.)

For simplicity of discussion, let's assume the earth disc is in the XY plane, at z=0. Also, let's assume a day/night cycle is 24 hours at your earth. A shadow always points towards where the Sun is not, so it rotates 360 degrees in one day/night cycle.

Depending on the trajectory of the Sun relative to the disc, you get different effects.

If you let the Sun rotate in the XY plane at z=100 (above the disc), your world has 24/7 day, and the shadow is visible all 24 hours. If you let the Sun rotate around the disc in the XZ plane, at Y=0, your world has 12 hours day, and 12 hours night. The shadow still rotates 360 degrees in 24 hours, but is not visible during the night. If you tilt the Sun trajectory, or move its center away from the center of the disc, day and night cycles shift accordingly.

If you put the Sun so far away that its entire trajectory is at one side of earth (say, the XY plane, z=100, x of the center is 1,000,000,000), the shadow just moves back and forth between two angles.

I would expect that the Internet knows exactly what the trajectory of the Sun is relative to Earth in case you're interested, it's not very simple though, our disc rotates around itself in 24 hours, but we're tilted while we orbit around the Sun, which causes our seasons.

Edited by Alberth

##### Share on other sites

In your game, if you want to display the time of the day, interpolate the position of the sun between reference points like sunrise, midday and sunset. You can approximate Earth as a sphere, Sun movement as a circular equatorial orbit of radius 1 AU and duration 24 hours, and your game environment as a negligibly small part of the tangent.plane at a certain latitude and longitude; calculating the position of the sun relative to your plane is easy

You can use astronomical data for reference: at a given time of the year, what are the times of sunrise and sunset at the latitude where the game takes place?

##### Share on other sites

as you can never see the sun, and it is for this purpose safe to assume it is infinitely far away, all you need is a single 3d-rotation-vector which you rotate as the day passes. project your shadows accordingly and play with the rotation to get the right length of day/night-cycle. (probably want the the day to be longer than it actually is). by project i mean that if the rotation-vector points downward, make shadows short, if points to the side, make em longer. no need to do astronomical calculations really.

1. 1
2. 2
Rutin
21
3. 3
4. 4
A4L
15
5. 5

• 13
• 26
• 10
• 11
• 9
• ### Forum Statistics

• Total Topics
633736
• Total Posts
3013605
×