Godot Version
4.4 Stable
Question
Hello, I’m new here and I have been working on a Top-Down Shooter in the style of games such as Smash TV and Total Carnage in Godot 4.4. The game uses the resolution of 640x360 with 16x16 tiles. I have been making a system where the player camera snaps to a room based on if the player leaves the designated resolution (640x360). 16x16 tiles don’t perfectly fit onto the screen which led me to adjust the camera where 4 pixels are cut off from the top and bottom to perfectly align the tiles to match.
In the script for the camera which is a child of the player node, I have the process function and an update_screen function that controls the camera view port and when the camera should shift to the next screen based on the player’s location. Some rooms need to have a free moving camera with limits so the cam_lock if statement needs to stay.
What I have noticed is that the further vertically the player travels, the more de-synced and off center the camera shift point is from the edge of the screen. It should be that the middle of the player touching the edge of the screen is what switches the camera to the next screen. Is there something I could change about my equations so the edge of the screen will align with when the camera shifts? What I did for the camera global_position in the update_screen function is an example of what I would be talking about.
In the video example below you can see how the area where the camera should be shifting moves further up the y-axis as the player continues. It should be aligned with the edge of the screen. I know this is happening due to the screen_size = (640,360). Is there a way to adjust the point at which the camera shifts to same coordinates where the edge of the screen would be?
Thank you all very much!
var screen_size = 0
var cur_screen := Vector2(0, 0)
var parent_screen := Vector2(0, 0)
@export var cam_lock = true;
func _ready():
screen_size = Vector2(640,360)
set_as_top_level(true)
global_position = get_parent().global_position
func _process(_delta) -> void:
if (cam_lock != false):
parent_screen=(get_parent().global_position/(Vector2(screen_size.x,screen_size.y))).floor()
#checks if the current screen is equal to the screen where the player is located.
if not parent_screen.is_equal_approx(cur_screen):
_update_screen(parent_screen)
else:
set_position(TargetNode.get_position().round())
global_position = global_position.round()
#Updates what screen the camera is locked to.
func _update_screen(new_screen : Vector2):
cur_screen = new_screen
global_position = Vector2(cur_screen.x,cur_screen.y)*screen_size+screen_size*0.5
global_position.y -= 4*(cur_screen.y+(cur_screen.y-1))