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.92k stars 62 forks source link

2D Follow Physics Interpolation #294

Closed ramokz closed 1 month ago

ramokz commented 1 month ago

[!IMPORTANT] Both Godot 4.2 and 4.3 are supported, however the enhancements here will only work for Godot 4.3 dev6 or later.

[!IMPORTANT] The changes only affect 2D scenes. 3D phyics interpolation are not yet supported in Godot and will be added in a future release.

What is this?

This change applies the newly added physics interpolation that was included in Godot 4.3 dev 6 release. The changes in this PR allows a PCam2D to support having a follow target of either a PhysicsBody2D-based or a non-PhysicsBody2D-based node, where the Camera2D will then automatically adjust its interpolation mode to match. Resulting in a jitter-free movement.

Before this, the user had to make use of either the smoothing-addon or implement their own solution to interpolate visuals as mentioned in the documentation.

For Godot 4.2

This release will still be compatible with Godot 4.2. It does a few checks to confirm the version and disables the added functionality while retaining existing behaviour. So nothing should be worse or better from this change.

[!NOTE] It will encourage to upgrade to Godot 4.3 if one attempts to select a PhysicsBody2D as a follow target or follow targets (Group Follow).

For Godot 4.3

Project Settings

### PhantomCameraHost ~~To enable the newly added physics interpolation, uncomment the following two lines inside `PhantomCameraHost.gd` on line `201` and `206`.~~ ```gdscript camera_2d.physics_interpolation_mode = Node.PHYSICS_INTERPOLATION_MODE_ON ``` ```gdscript camera_2d.physics_interpolation_mode = Node.PHYSICS_INTERPOLATION_MODE_OFF ``` Do no uncomment those lines in Godot 4.2 as that will likely crash the editor.

Known Issues

[!NOTE] All known issues have now been addressed.

Switching to a PCam2D that has a PhysicsBody2D follow target from another PCam2D that either has no follow target or a non-PhysicsBody2D follow target will cause a sudden camera flickering on the first few frames. The tween still triggers, but the effect is very noticeable and not good enough for release.

This appears to be due to setting the Camera2D's physics_interpolation_mode to Node.PHYSICS_INTERPOLATION_MODE_ON from having previously being Node.PHYSICS_INTERPOLATION_MODE_OFF.

Notes