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

Add Pixel Perfect following mode #156

Closed GrogsyShovel closed 9 months ago

GrogsyShovel commented 9 months ago

As of now, 2D cameras tween and lerp using standard Vector2s with floats for the x and y values. This can lead to incorrect rendering in viewport-scaled (usually pixel-art) games when the x or y value of the camera's position ends in .5:

image

In order to solve this problem, I created a new bool property shown in the inspector called pixel_perfect.

image

In phantom_camera_host.gd, I added a check for the new property in both the _follow_pcam and _tween_pcam functions. If Pixel Perfect following is enabled, the x and y float values of the current point in the lerp or tween will be rounded to the nearest integer. I also fixed a couple of small grammar mistakes in phantom_camera_2D.gd

The use case for this property is relatively obscure, but I hope it helps anyway!

Examples:

Before Pixel-Perfect following:

y value ends in .5 image x and y values both end in .5 image

After Pixel-Perfect following, the x and y values still both end in .5, but the camera host rounds each value to the nearest integer: image