Have function to set screen center to specific point #5098
azur-wolve
started this conversation in
Engine Core
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Recently used
Camera2D
with drag margins to move the camera when the mouse cursor is in the screen margins.Using a key to teleport the
camera.global_position
to a specific point.It does in an imprecise way.
The
camera.global_position
follows the mouse cursor, so the effective teleported position varies depending on where the mouse cursor is, presumably in a screen margin, while moving the camera.It teleports to the nearest point where the target position appears inside the screen.
To get the center of the screen have
camera.get_camera_screen_center()
.But to set the current center of the screen to a specific point, there's no built-in property or method.
An hypothetical
Camera2D.set_screen_center_to(target_pos: Vector2)
would solve the issue.Edited: solved with
camera.global_position += target.global_position - camera.global_position + (camera.get_camera_screen_center() - camera.global_position)
However a built-in function would be handy.
Beta Was this translation helpful? Give feedback.
All reactions