-
-
Notifications
You must be signed in to change notification settings - Fork 120
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Jitter when making the camera follow a physics object #211
Comments
I had the same problem and what worked for me was updating the camera on |
It does solve the issue when physics plugins are added like: app.add_plugins(PhysicsPlugins::new(FixedUpdate)); This works well enough, but it'd be nice if there is a better solution. Thanks @pintariching! |
Personally, I'm only getting the jitter if I run in debug mode with optimizations configured like this: [profile.dev.package."*"]
opt-level = 3 Some other people seem to be having the issue even with other configurations though, so it could be somewhat device/architecture specific, or maybe dependent on frame rate. We can keep this issue open until the proper reason and fix for the jitter is found |
You don't need to use fixed update, just the This ensures that the camera is updated once the object you're following is done with all of its transforming. I personally use the |
I made a repo with a few examples that all either jitter around or have jerky movement: https://github.com/pintariching/bevy_xpbd_jitter_test/tree/master/examples Here's the examples from my system with a Ryzen 5 3600, 32 GB, AMD Radeon RX 6950 XT running on PopOS 22.04 Wayland: Basic example: Screencast.from.01.11.2023.12.13.18.webmBasic example with no lerp: 2023-11-01.12-29-19.mp4Running camera logic in FixedUpdate: 2023-11-01.12-31-08.mp4Running camera logic in FixedUpdate after PhysicsSet::Sync 2023-11-01.12-32-15.mp4 |
Here's a link to my repo with a similar issue I think, video included tbillington/driving-physics-repro#1 |
The jitter is caused by the camera's position lagging on frame behind the player. The issue is that the camera follow system needs to:
The following ordering constraints should fix the issue. .add_systems(
PostUpdate,
camera_follow_player
.after(PhysicsSet::Sync)
.before(TransformSystem::TransformPropagate),
) |
This solves the issue completely, and it's explained perfectly. Thanks @devil-ira! |
@Jondolf Could you add this hack somewhere in docs please? ❤️ 🙏 |
Sure, I'll put it in the docs for the next release |
# Objective #211 has a solution for camera jitter when following physics entities: #211 (comment) This is such a common issue that it should at least be mentioned in the FAQ. ## Solution Add solution for camera following jitter to documentation FAQ.
anyone still having jitter problem after applying the hack? .add_systems(
PostUpdate,
camera_follow_player
.after(PhysicsSet::Sync)
.before(TransformSystem::TransformPropagate),
) I still got the problem... It seems that whether write this code or not doesn't change anything?? Also that my jitter problem isn't "always" there, no matter the above code is applied or not. Sometimes if you walk around for a while, it will become without jitter. by the way, I’m using Dolly, so my code is in fact: app.add_systems(
PostUpdate,
(update_camera, Dolly::<MainCamera>::update_active)
.chain()
.after(PhysicsSet::Sync)
.before(bevy::transform::TransformSystem::TransformPropagate),
); I can also confirm that if in dev profile, with And even it it's in dev profile, no opt-level, sometimes I still got the jitter. Seems it randomized for each run. Ok, I'm just reporting what I'm experiencing now. I'm using Ok, I got my partial answer here. At least it's an avian problem. I just replaced the whole avian dependency with rapier3d counterpart. The codes are very alike, and the result is different. Rapier3d is more stable. No jitter at all! |
|
By replacing the same code with Rapier counterparts, it's easily confirmed that it's not related to any other codes. Closed issue will need to be reopened if the issue is not fixed entirely, and in my case this worth investigating. Saying don't respond to oneself's comment will make people feel unwelcomed since people only be here to be helpful to something. And it might reflect the possibility that one thinks he is absolutely right, without any chances to be argued, which is not true. Also, I can say the same thing to you, please don't respond to this. But I guess that won't work right? Just don't be personal against any people who only wants to help you. The jitter proplem is not in bevy I can confirm this. Because When I Stop using any physic engine, the issue is gone. (By manually apply the same value directly to the camera and the object. |
|
@numfin You're coming off a bit hostile here, please try to be a bit more welcoming in the future :) Their question is fair and might not strictly be a Bevy issue. I do agree with you that it would be preferable to open a new issue though, ideally with a minimal reproduction. @xx1adfasd It's hard to say what the issue could be without a reproduction and/or video. If the "jitter" is just periodic stutters roughly once or twice a second, it could be related to Avian running physics at a fixed timestep by default, like most engines. This causes an issue where physics can run more than one time on some frames, and zero times on others, causing a visible stutter. The common fixes to this issue are:
If you don't get the issue in Rapier though, it's very possible that it's a different problem. In that case I would suggest opening a new issue like @numfin mentioned. It is unclear if the jitter is related to camera following, which this issue is about, so it's better to document and investigate in its own issue. |
Hi, I'm trying to make the camera follow a physics object using this system:
which is added to the application using:
but I end up getting jitters. What's the proper way to solve this?
Here is the issue visualized:
(it's even worse in the actual game that I'm working on)
And the minimal reproduction code:
The text was updated successfully, but these errors were encountered: