RTS-Camera2D icon indicating copy to clipboard operation
RTS-Camera2D copied to clipboard

Sticky map edges

Open sadovsf opened this issue 5 years ago • 2 comments

I have found that camera implementation does not check for limit values (limit_left, limit_right...) of Godot camera resulting in position being moved but view is stuck properly on the limits. This results in user essentially overscroll map and then having to scroll back while screen is still on limit position.

Proposal: When camera reaches limit in one of the axes it should no longer set its position further behind these limits

sadovsf avatar May 05 '20 08:05 sadovsf

You can update the script to the following just after updating position based on movement in the _physics_process(delta) function inside of RTS-Camera2D.gd:

        # Update position of the camera.
	position += camera_movement * get_zoom()

	var zoom = get_zoom()
	var viewport = get_viewport_rect()
	var actual_left_limit = viewport.end.x * zoom.x / 2
	var actual_top_limit = viewport.end.y * zoom.y / 2
	
	position.x = clamp(position.x, actual_left_limit, limit_right - actual_left_limit)
	position.y = clamp(position.y, actual_top_limit, limit_bottom - actual_top_limit)

I'd make a PR but I don't have my env set up to do that at the moment. I believe this will take zoom into account correctly. Haven't tested much beyond my current use case.

yaegerbomb avatar Oct 07 '23 23:10 yaegerbomb

The real fix for this:

You can update the script to the following just after updating position based on movement in the _physics_process(delta) function inside of RTS-Camera2D.gd:

#  Update position of the camera.
position += camera_movement * get_zoom()

# force camera to center of screen positionally
var center = get_screen_center_position()
var current_target = get_target_position()
if current_target != center:
    position = center

For godot 4 at least.

yaegerbomb avatar Oct 20 '23 21:10 yaegerbomb