How can I limit the camera movement?

Godot Version



I’ve been trying to create a camera that follows the mouse to an extent similar to nuclear throne.

What i’m struggling with is that in the current implementation the camera keeps following the mouse past the point where I want it. For the most part the camera does work like in nuclear throne and it’s pretty good but if like me you have 2 monitors and move the cursor to the other monitor the camera will move way past where it should be and the player character won’t even be on the screen anymore. Can I limit this movement somehow?

Here’s a screenshot to show what I mean. The camera should be capped at a certain distance from the player but still be able to move freely in that area.

I have tried adding together your code with my own but the camera starts like this and the player is in the top left corner, not really sure why.

I managed to solve it on my own by clamping the local mouse position.

1 Like

Hello, I actually did use the camera limits to constrain the camera within the bounds of the playable level, so it’s a nice combo of the two.