Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sticky map edges #3

Open
sadovsf opened this issue May 5, 2020 · 2 comments
Open

Sticky map edges #3

sadovsf opened this issue May 5, 2020 · 2 comments

Comments

@sadovsf
Copy link

sadovsf commented May 5, 2020

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

@yaegerbomb
Copy link

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 added a commit to yaegerbomb/RTS-Camera2D that referenced this issue Oct 20, 2023
@yaegerbomb
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants