#camera laggin behind

4 messages · Page 1 of 1 (latest)

round flint
#

I have a character that is moved by user and a separate camera that follows character.
But when character is moving, it seems like camera is one frame behind. Am I missing something?

Code:

...
fn setup(...) {
    // player
    commands
        .spawn(Player)
        .insert(PbrBundle {...})
        .insert(TransformBundle::from(Transform::from_xyz(0.0, 2.0, 0.0)))
        .insert(RigidBody::KinematicPositionBased)
        .insert(KinematicCharacterController::default())
    ...
    //camera
    commands.spawn(Camera3dBundle {
        transform: Transform::from_xyz(-9.0, 9.0, 9.0).looking_at(Vec3::ZERO, Vec3::Y),
        ..default()
    });
}
fn follow_player(
    player_transforms: Query<&Transform, With<Player>>,
    camera_offset: Res<CameraOffset>,
    mut camera_transforms: Query<
        &mut Transform,
        (With<Camera3d>, Without<Player>, Without<PointLight>),
    >,
) {
    let player_transform = player_transforms.single();
    let mut camera_transform = camera_transforms.single_mut();

    camera_transform.translation = player_transform.translation + camera_offset.0;
    camera_transform.look_at(player_transform.translation, Vec3::Y);
}
...
app.add_systems(FixedUpdate, (move_player, follow_player).chain());

[dependencies]
bevy = { version = "0.12.1" }
bevy_rapier3d = { version = "0.24.0", features = ["parallel"] }

I'm using rapier KinematicCharacterController, maybe that has any effect?
Tried to remove "parallel" from bevy_rapier3d, but that had no effect.

Also, new to Rust so might be dumb question

torpid falcon
#

And if you are checking for keyboard inputs etc in move_player you probably should move it to Update as well in order not to miss input events

round flint
#

Yeah, I was using Update instead of FixedUpdate before, but that made camera jitter, but now after changing back to Update it's smooth. Can you link to some explanation of what .after(PhysicsSet::Writeback).before(TransformSystem::TransformPropagate) does?