bevyengine / bevyengine/bevy

SunPath Component + SunPathPlugin

Open
#20,613 2 comments 0 reactions 0 assignees View on GitHub
A-Rendering C-Feature S-Ready-For-Implementation X-Contentious
Dominant language
Rust
Stars
48.2k
Forks
4.8k
Avg merge
3d 22h
Merged PRs (30d)
161

Description

## What problem does this solve or what need does it fill?

Bevy has a physically based atmosphere but no built-in way to drive a physically correct sun arc. If the sun is static, that’s fine. But for dynamic day/night cycles, every project need to reimplement the same trigonometry (latitude/season/time -> light rotation).

## What solution would you like?

A single component + a plugin with one system. Works with any entity that has a `Transform` (most commonly a `DirectionalLight`):

```rust
#[require(Transform)]
pub struct SunPath {
pub latitude: f32,
pub declination: f32,
pub hour_angle: f32,
}

pub struct SunPathPlugin;

impl Plugin for SunPathPlugin {
fn build(&self, app: &mut App) {
app.register_type::()
.add_systems(PostUpdate, apply_sun_path);
}
}

fn apply_sun_path(
mut q: Query<(&SunPath, &mut Transform), Changed>,
) {
for (s, mut tf) in &mut q {
// compute rotation from (latitude, declination, hour_angle)
// tf.rotation = ...
}
}
```

The proposed approach/names/fields are not final, just general idea. We can add helper functions to instantiate SunPath easily based on developer preferences, for example:

- From latitude and season angle (or day of year);
- From desired day length (hours of daylight);
- From desired sunrise/sunset azimuth;
- From target noon altitude.

The plugin does not control time. It provides the simplest interface to orient the sun along physically correct arc based on game’s internal time model.

Minimal example:

```rust
app.add_plugins(SunPathPlugin);
app.add_systems(move_sun);

commands.spawn((
DirectionalLight { ... },
Transform::default(),
SunPath::from_latitude_season_hour(52.23, 0.65, 6.0)
));

fn move_sun(mut q: Query<&mut SunPath>, time: Res

## What alternative(s) have you considered?

Keep out of bevy repo, have separate repo/plugin for it.

---

I'm wondering if such minimal implementation could be valuable enough to be included in bevy repo.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.