I'm having a bit of trouble with jitter when setting the linear velocity as part of my kinematic character controller in Avian.
I've tried most solutions I can find here, and the Avian recommendation for system ordering but no luck.
I've attached a video which shows some of the jitter but it is **WAY ** worse in real life, perhaps due to the frame rate of the recording.
The jitter mostly goes away if I update the player transform directly according to intent and delta time. But this causes wonky physics.
I use a pixel camera and I've tried adding translation interpolation.
To give a rundown, I have my Player which sets a movement_intent each frame in Update (also tried earlier):
fn update_movement_intent(
mut query: Query<(&ActionState<PlayerAction>, &mut CharacterController)>,
) {
for (action, mut controller) in &mut query {
controller.movement_intent = action
.clamped_axis_pair(&PlayerAction::Move)
.normalize_or_zero();
}
}
The LinearVelocity is set according to movement_intent in Update:
fn movement(mut controllers: Query<(&mut LinearVelocity, &CharacterController)>) {
for (mut linear_velocity, controller) in &mut controllers {
**linear_velocity = controller.movement_intent * controller.speed;
}
}
The camera is smoothed towards the player in PostUpdate after PhysicsSet::Sync and before TransformSystem::TransformPropagate:
fn move_tracking_camera(
mut camera: Query<(&mut Transform, &TrackingCamera), Without<CameraTarget>>,
target: Query<&Transform, (With<CameraTarget>, Without<TrackingCamera>)>,
time: Res<Time>,
) {
// Get the target and camera translation (discord character limit)
let Vec3 { x, y, .. } = target.translation;
let direction = Vec3::new(x, y, camera.translation.z);
camera.translation = camera
.translation
.lerp(direction, time.delta_seconds() * config.decay_rate);
}