+1 vote

I have a script that uses translate() to move the camera with the mouse, and the camera is limited to a specific area of the level but when the camera reaches those limits and if the player where to try to move the camera beyond the limits, the camera gets a bit stuck when trying to move away from the limits.
Here is a video of the issue, sorry about the weird size or the capture I don't know why it's doing that: https://imgur.com/a/d1pnLZA

Thanks in advance.

Godot version version 3.4
in Engine by (58 points)

1 Answer

+2 votes
Best answer

This is because you dont limit the cameras position,
the camera itself is still moving beyond the limits but the viewport isnt.
try something like this:

position = Vector2(clamp(position.x,limit_left+get_viewport_rect().size.x/2,limit_right-get_viewport_rect().size.x/2),clamp(position.y,limit_top+get_viewport_rect().size.y/2,limit_bottom-get_viewport_rect().size.y/2))

This will use the limits you gave the camera.

by (60 points)
selected by
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.