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

Camera infinitely moving position when a second PhantomCamera2d with collision shape limit node is added to scene #170

Closed marvfash closed 9 months ago

marvfash commented 9 months ago

Issue description

Immediately I updated to 0.6.2.1, I noticed I could no longer use collision shape limit node targets multiple PhantomCamera2D in a scene. The moment I create a second camera and add a limit node to it, the camera just continues to move itself to a far position.

I use Godot 4.2

https://github.com/ramokz/phantom-camera/assets/58770266/3db92ee4-a6eb-4317-a993-65a3e196dc4d

Steps to reproduce

I also added a minimal project. Check the transform of the second camera and you will see it just keeps moving.

(Optional) Minimal reproduction project

PhantomCameraBug.zip Attached is a sample project.

marvfash commented 9 months ago

After more deepdive I discovered it only happens to PhantomCamera2Ds with lower priority. The highest priority camera never get affected. Once you change the priority of the active pcam to lower than other cameras, the camera will start experiencing the bug.

For example, if you have 3 PhantomCamera2Ds with priority; camera1 : priority = 2, camera2 : priority = 1, camera3 : priority = 3

The bug will only affect camera2 and camera3 since they have lower priority than camera1. If you update the priority of camera1 to 0, the bug will no longer affect camera3 since it now has the highest priority, but it will now affect camera1 and camera2.

I'm still doing some investigation to see if I can find a fix for it.

marvfash commented 9 months ago

Just discovered it works as intended if the collision shape is not a child of the camera. I just checked the example in the addon and I might have set it up the wrong way.

ramokz commented 9 months ago

Yeah, so the setup you show in the initial video wouldn't work because you're effectively attaching the bounding box (CollisionShape2D) to the thing that moves (PCam2D). So whenever the PCam2D moves, so too does the thing that constrains it.

The demo scene, as you also mention, shows how you would use the CollisionShape2D with a PCam2D. It's meant to confine the PCam2D to a specific area of a 2D scene, which ideally should be a sibling CollisionShape2D within a Area2D node.

marvfash commented 9 months ago

Yeah, figured it out. To make my scene tree cleaner, I eventually added it as a child of the PCam2D but set it as top level so the PCams movement does not affect it.

ramokz commented 9 months ago

Nice, glad to hear it got resolved!