#Weird shadow cutting

2 messages · Page 1 of 1 (latest)

restive robin
#

So I made the code for a planet like structure that orbits around my player even tho is a sun.
The thing is as I move around my camera well shadows get cutted any ideas on what causes this?

/// Will add lighting to the sun
fn add_cosmetic_sun(
    suns: Query<Entity, Added<SunMarker>>,
    mut commands: Commands,
    mut meshes: ResMut<Assets<Mesh>>,
    mut materials: ResMut<Assets<StandardMaterial>>,
) {
    for sun in suns.iter() {
        let sun_light = DirectionalLightBundle {
            directional_light: DirectionalLight {
                illuminance: light_consts::lux::OVERCAST_DAY,
                shadows_enabled: true,
                ..default()
            },
            transform: Transform::from_xyz(0.0, 4.0, 0.0),
            cascade_shadow_config: CascadeShadowConfigBuilder {
                first_cascade_far_bound: 4.0,
                maximum_distance: 10.0,
                ..default()
            }
            .into(),
            ..default()
        };
        commands
            .entity(sun)
            // .insert(PbrBundle {
            //     mesh: meshes.add(Cuboid::default()),
            //     material: materials.add(Color::srgb(1.0, 1.0, 1.0)),
            //     ..default()
            // })
            .insert(sun_light)
            .insert(Orbit {
                center: Vec3::new(0.0, 0.0, 0.0), // Orbit center point
                radius: 5.0,                      // Orbit radius
            });
    }
}

}```
#
fn orbit_around_point(
    mut query: Query<(&mut Transform, &Orbit)>,
    // time: Res<Time>,
    cycle_time: Res<CycleTimer>,
) {
    for (mut transform, orbit) in query.iter_mut() {
        let cycle_fraction = cycle_time.0.elapsed_secs() / cycle_time.0.duration().as_secs_f32();

        // Calculate the angle (2π radians) * cycle_fraction, moving 1/24 of the orbit each hour
        let angle = cycle_fraction * 2.0 * std::f32::consts::PI;

        // Calculate the new target position using trigonometric functions
        let target_position = Vec3::new(
            transform.translation.x,
            orbit.center.y + orbit.radius * angle.cos(),
            orbit.center.z + orbit.radius * angle.sin(),
        );

        // Smoothly interpolate between the current position and the target position
        transform.translation = transform.translation.lerp(target_position, 0.1);

        transform.rotation = transform
            .looking_at(Vec3::new(0.0, 0.0, 0.0), Vec3::Y)
            .rotation;
    }```