#camera stutter, updated

7 messages · Page 1 of 1 (latest)

cyan flicker
#

I am still having issues with camera stutter, it is now on the update schedule and this is the updated code

    time: Res<Time>,  // Access the delta time resource
    mut query1: Query<&mut Transform, (With<MainCamera>, Without<Player>)>,
    query2: Query<&Transform, (With<Player>, Without<Camera>)>
) {
    if let Ok(mut cam_trans) = query1.get_single_mut() {
        if let Ok(player_trans) = query2.get_single() {
            let target_position = player_trans.translation + Vec3::new(10.0, 10.0, 10.0);
            
            // Control the speed and smoothness with delta time
            let smooth_factor = 5.0;  // Adjust this for more or less smoothing
            let interpolation_factor = 1.0 - f32::exp(-smooth_factor * time.delta_seconds());

            // Calculate the new interpolated position
            let new_position = cam_trans.translation.lerp(target_position, interpolation_factor);

            // Apply some minimum distance threshold to prevent jitter from tiny updates
            if (new_position - cam_trans.translation).length() > 0.001 {
                cam_trans.translation = new_position;
            }
        }
    }```
opal totem
#

could you print the interpolation_factor to see if it oscilates in a periodic pattern?

cyan flicker
#

it does appear to have some amount of oscilation

Interpolation Factor: 0.080257475
Interpolation Factor: 0.07362163
Interpolation Factor: 0.079624474
Interpolation Factor: 0.078888774
Interpolation Factor: 0.07367486
Interpolation Factor: 0.07762092
Interpolation Factor: 0.08667457
Interpolation Factor: 0.06648147
Interpolation Factor: 0.09625405
Interpolation Factor: 0.082118034
Interpolation Factor: 0.07394904
Interpolation Factor: 0.09676677
Interpolation Factor: 0.07977587
Interpolation Factor: 0.067284465
Interpolation Factor: 0.08950919
Interpolation Factor: 0.06327546
Interpolation Factor: 0.088678956
Interpolation Factor: 0.077483475
Interpolation Factor: 0.067860246
Interpolation Factor: 0.07738292
Interpolation Factor: 0.088671625
Interpolation Factor: 0.07201064
Interpolation Factor: 0.094072044
Interpolation Factor: 0.0766418
Interpolation Factor: 0.08491701
Interpolation Factor: 0.07809812
Interpolation Factor: 0.09488386
Interpolation Factor: 0.06361258
Interpolation Factor: 0.07361233
Interpolation Factor: 0.09223747
Interpolation Factor: 0.069814265
Interpolation Factor: 0.07524878
Interpolation Factor: 0.09733564
Interpolation Factor: 0.064697266```
opal totem
#

this is already using the smooth lerp from Freya's talk right?

cyan flicker
#

no I didn't see that, this uses an ordinary lerp

opal totem
#

i saw the exp and thought it was the lerp that Freya showed on a talk that she did, lemme get the link