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

Calling set_follow_target_offset breaks Phantom Camera initial properties #159

Open madeleineostoja opened 7 months ago

madeleineostoja commented 7 months ago

Issue description

Disclaimer that I'm a software engineer who's pretty new to Godot & gamedev in general so this could be user error, but I'm trying to create a simple "look ahead" type behaviour with a PhantomCamera2D, and calling set_follow_target_offset from a signal that's called when the player's direction changes seems to reset all initial properties on my phantom camera (eg: damping, framed follow dead zone, etc).

Steps to reproduce

  1. Setup a PhantomCamera2D with Framed follow mode on a player object and camera damping
  2. Call set_follow_target_offset
  3. See initial camera behaviour be broken

Code:

@export var camera_offset = 100
@onready var camera: PhantomCamera2D = $PhantomCamera

func _on_player_direction_changed(direction: Vector2) -> void:
  camera.set_follow_target_offset(direction * camera_offset)

Behaviour:

https://github.com/ramokz/phantom-camera/assets/6374876/3149a47c-a5b4-4981-a2b1-c732a6737337

(Optional) Minimal reproduction project

No response

ramokz commented 7 months ago

That sounds odd! Nothing should be resetting any of the initial properties by changing the follow_target_offset.

Does this also happen when using the Simple Follow mode, or if you greatly reduce the camera_offset amount?

My best guess would be that it's related to the Framed Follow logic specifically. Where the target position that is being tracked, and in your case offset, exceeds the bounds of the Dead Zones, which can cause its follow logic to effectively break. This is not an uncommon issue, and is likely what you're seeing, though it's hard to say exactly without debugging it. The Framed Follow does need a proper makeover, as it has been running into various issues, among this (assuming that is the cause behind it).

Funnily enough, the day after this was posted, a PR was set up to support Look Ahead (#160), so there is at least a plan for getting built-in support for it. Though I very much doubt it would be a silver bullet for Framed Follow if, again, that is indeed the root cause here.

madeleineostoja commented 7 months ago

My best guess would be that it's related to the Framed Follow logic specifically. Where the target position that is being tracked, and in your case offset, exceeds the bounds of the Dead Zones, which can cause its follow logic to effectively break.

Yep! Looks like this is the issue. Both reducing camera_offset to a small value (which doesn't move the camera offset at all, I assume because of the same edge case?) and changing to simple follow seems to fix the issue

For now the framed follow is more important for my use case, but I'll keep an eye on the PR for look ahead and see if it gets support for framed follow

ramokz commented 7 months ago

I'll try and shift priorities around and do a proper refactor for Framed Follow in the not too distant future. Been seeing more issues popping up for it lately.

madeleineostoja commented 6 months ago

Thank you! I’m not deep enough in Godot yet to offer help on a PR but happy to test and debug if needed

ramokz commented 6 months ago

Would be great to have additional eyes on it to make sure it works correctly!

Will make a draft PR at some point and link back to it here, and in the other issues, once I get around to it.