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
2.18k stars 72 forks source link

Framed mode changes vertical axis camera position when not supposed to if out of horizontal bounds. Godot 4.1 #144

Open KayCat88 opened 10 months ago

KayCat88 commented 10 months ago

Issue description

I have the vertical dead zone set to a size which makes it so when the character jumps, it doesn't move the camera. However, if the character is moving out of the horizontal bound and the camera is following it, the camera moves vertically when the player jumps, which doesn't happen if the player is still (due to the aforementioned vertical dead zone size). I've found that this also occurs with the horizontal axis. I don't know if this is intended to happen, but I assume not. My apologies if it is. image

https://github.com/ramokz/phantom-camera/assets/131679960/95c8ae74-cab9-49b4-8470-8e8693e37ddd

Steps to reproduce

To reproduce this, the only things necessary are the following.

(Optional) Minimal reproduction project

Framed Mode.zip

ramokz commented 10 months ago

Correct, it is not an intentional result of the feature, but rather a shortcoming that's still being figured out.

Another thing I spotted in your video example is that the target seems to have exceeded the bounds of the dead zone. Though I'm not quite sure how that occurred, since nothing unusual appeared to happen as you moved the character around?

Sarrg commented 7 months ago

I think this is the same issue as I was having right now. The cause for this is that there is only a check if the target is touching a deadzone and disregards on which axis. Thus the global position is updated to the target_position. What need to be done is that global position horizontally (x position) is only updated when the horizontal dead zone is reached and the same for the vertical.

My quick fix for this is to add the following to phantom_camera_2D.gd:523:

if offset.x == 0:    # offset = Properties.get_framed_side_offset() 
    target_position.x = get_global_position().x
if offset.y == 0:
    target_position.y = get_global_position().y

and remove the else to always update _camera_offset.

A more proper fix would be to only store _target_position_with_offset() as _camera_offset and then do:

target_position = get_global_position() + abs(Properties.get_framed_side_offset()) * (_target_position_with_offset() - _camera_offset)