bevy_third_person_camera icon indicating copy to clipboard operation
bevy_third_person_camera copied to clipboard

Just early attempt at some sort of physics engine checker

Open Sirmadeira opened this issue 1 year ago • 6 comments
trafficstars

Will add example, to check if it avoids jittering or not

Sirmadeira avatar Apr 09 '24 21:04 Sirmadeira

@AndrewCS149 Please check it out and give me some good critique

Sirmadeira avatar Apr 09 '24 21:04 Sirmadeira

@Sirmadeira thanks for the PR. I will check this out tomorrow

The-DevBlog avatar Apr 10 '24 03:04 The-DevBlog

@Sirmadeira

Im a little concerned with adding bevy rapier as a dependency. I would ideally like to leave that out. Im wondering if there is another way to approach the problem so that we can avoid adding bevy rapier. Could you post a screenshot/video someone demoing the issue that you are facing so I can better understand what you are trying achieve? I'd definitely love to work with you on this and figure out a solution.

The-DevBlog avatar Apr 11 '24 02:04 The-DevBlog

The issue is simple and it is also described at bevy xpbd docs at https://docs.rs/bevy_xpbd_2d/latest/bevy_xpbd_2d/#why-does-my-camera-following-jitter

Basically since the most physics systems are stored in the PostUpdate status system, the transform of the camera and the player often jitter because of 1 frame delays.

impl Plugin for CameraPlugin {
    fn build(&self, app: &mut App) {
        app.add_systems(Startup, spawn_camera);
        app.add_systems(Update, 
        (toggle_cursor,
        orbit_mouse.run_if(orbit_condition),
        zoom_mouse.run_if(zoom_condition))
        .chain());
        app.add_systems(Update, sync_player_camera.after(PhysicsSet::StepSimulation));
    }
}

So a simple app system like this if it runs the sync_player_camera in Update the player entity will jitter a lot. If a characters movement is physics engine dependent. Perhaps finding a bevy system that is guaranteed to run after the physics systems in rapier or xpbd would be the ideal solution. But I tested so many pre-available and couldn't find one that fits the category. Perhaps creating a manual one could avoid importing the engine as an dependency. I will take a shot at it It wont occur in controllers made solely using bevy which are rare to be honest. Here is a sample video

Gravação de tela de 11-04-2024 12:56:41.webm

Sirmadeira avatar Apr 11 '24 16:04 Sirmadeira

@Sirmadeira

Okay I see. Yeah that is very clearly an issue. I'm going to do my best to look at this tonight. Just bear with me as my work schedule has been a little hectic this week.

The-DevBlog avatar Apr 11 '24 19:04 The-DevBlog

@Sirmadeira

HUGE apologies on the massive delay. I began working this last night. Would you be able to provide a sample repo that I could checkout? Im having difficulties reproducing the issue. I added a Rigid Body and a Collider to my player entity, but im not seeing any frame jittering.

The-DevBlog avatar May 03 '24 13:05 The-DevBlog