#Jittery movement with moving camera

6 messages · Page 1 of 1 (latest)

wet yarrow
#

Hi, I have a game where characters are moving; their movements are not constrained, and use floating point values.

I noticed that when I attach a camera to a player position, the other players' movements become slightly jittery (the player being followed is smooth). When the camera is fixed, there is no jitter.

My characters are moving during FixedUpdate.
During PostUpdate, I attach the camera to the main character's Transform.

Here's my system ordering:

  • FixedUpdate: main player position gets updated
  • Update: other players' position gets updated (interpolation)
  • PostUpdate (before TransformPropagate):
    • set the camera Transform to the main player's position
    • draw gizmos

I am wondering:
A) what is the reason for this? I found this thread: https://www.reddit.com/r/gamemaker/comments/pcz8qc/camera_has_jittery_movement_when_the_player_is/
https://forum.gamemaker.io/index.php?threads/why-my-movement-is-jerky-for-speed-of-fraction.95757/
that suggests that it's because the camera has to render a fixed number of pixels, so fractional values in the Transform cause some issues

B) what can I do to fix this? Is this a common gamedev thing?

wet yarrow
#

You can reproduce it by going in this repo: https://github.com/cBournhonesque/lightrider/tree/main

  • server: go to the server folder and run cargo run -- headless
  • client: go to the client folder and run cargo run -- -c 1
  • run a second client with cargo run -- -c 2
    Then you can see the flickering. You can press T to toggle the camera follow mode
GitHub

Contribute to cBournhonesque/lightrider development by creating an account on GitHub.

wet yarrow
#

I think it ultimately stems from the fact that:
i have separate independent prediction and interpolation times
they tick at roughly the same rate, but they cross tick boundaries at different times:
Frame 1: interp_tick: 1 predicted_tick: 1
Frame 2: interp_tick: 4 predicted_tick: 3
Frame 3: interp_tick: 6 predicted_tick: 6
my predicted player (controlled character) is updated during FixedUpdate (on the predicted tick)
my interpolated player (other players) are updated during Update (on the interpolation tick)

When the camera is fixed the jitter is not really noticeable but when I follow the main player on the predicted tick, it is because the other players sometimes do only 2-tick updates when the predicted does 3 ticks, and vice-versa

gray wigeon
#

I had a similar issue (apologies if I ever said this spiel to you, I think I've told it to a couple people haha) - and I believe you are absolutely correct. I don't have any specific fix for interpolation & prediction - but it stands to reason we see any discontinuity in updates as jitter

#

For instance, I just got a 144hz monitor, and 90fps can look like butter, but if I raise a games framerate to 120fps and it bobs between 100-120fps, it will look like garbage, even though the update rate is higher

#

specifically, if the camera has an update rate != to other objects, that will create jitter (n.b. I'm having trouble convincing myself this explains "the player being followed is smooth" -- hypothesis: if you add smoothing to the camera, you'll probably see the player jitter too)