ramokz / phantom-camera

👻🎥 Control the movement and dynamically tween 2D & 3D cameras. Built for Godot 4. Inspired by Cinemachine.
https://phantom-camera.dev/
MIT License
1.97k stars 65 forks source link

Jittery camera movement #173

Closed HappyHeads closed 6 months ago

HappyHeads commented 6 months ago

Issue description

I have a 144hz monitor and camera movement is very jittery in 3D and 2D when I have VSync on or framerate cap at an odd number. From my limited testing it seems to be an issue when the physics process happens at a different framerate compare to the monitors refresh rate. One way I found to solve the issue is to change _process inside phantom camera code to _physics_process but I'm not sure if there are any side effects to doing that. I know that physics jitter is a known issue with Godot itself but I wonder if there is specific ways to properly avoid it with phantom camera since its going to be a problem if players will have inconsistent framerate too.

Steps to reproduce

(Optional) Minimal reproduction project

No response

ramokz commented 6 months ago

Thanks for reporting this! This was an issue early on in the project, but had a hunch there were still things to do for this.

So have tested on both a 120hz and 60hz monitor.

Can't seem to replicate any jitter when V-Sync is enabled, or disabled, on either monitor — it has apparently been enabled for me the entire time. Not sure if the reason you're seeing it is due to having a higher refresh rate than me, though annoyingly can't check that.

But can see what you mean regarding the uneven / non-divisible by 60 physics tick per second value. The concern about _physics_process should only be for the Camera2D/3D itself, within the PhantomCameraHost.gd, which should ideally be kept in the _process. The addon was initially using the _physics_process to move the Camera2D/3D, again, within PhantomCameraHost.gd. It was changed to only move in the _process after the _physics_process had run because it caused issues at certain monitor refresh rates, typically highers ones.

However, moving the PhamtomCamera2D/3D positional changes to the _physics_process does seem stable in any physics tick per second value when checking on both monitors and on two devices. So your suggestion seems like a valid solution to try out. If anything, it looks better than the existing one.

ramokz commented 6 months ago

I'll make a PR and try to gather some feedback for about a week or so.

If no one screams or shouts about it, I'll merge it in and submit an update.

P5ina commented 6 months ago

This is not a problem of phantom camera, you should tween your visuals in process. I have the same issue and I resolved it by using this library (I found it on godot's docs page). But to work this with phantom camera you need to use my PR #179 that fixes camera being affected by _physics_process

Lasuch69 commented 6 months ago

Mind that when using Third Person Mode, spring arm causes a bit of jitter too.

ramokz commented 6 months ago

Resolved in #179