Camera2d gets stuck when I try to dynamically change camera limits and its been troubling me for days

Thanks for the screenshots, they actually confirmed what we needed to narrow down the issue.

In your first image, if you look at the ruler along the top, the room’s left wall is around x = 450 and the right wall is around x = 650. That means the room is roughly 200 pixels wide in world coordinates.

Now compare that to the limits you’re setting:

LimitLeft   = 450;
LimitRight  = 460;
LimitTop    = 635;
LimitBottom = 655;

Those limits only define a 10×20 pixel rectangle, which is far too small for the camera’s visible area. That could explain why the camera gets pinned to one corner.

To determine the correct limit values, could you provide the following?

  1. The room’s world coordinates: left, right, top, and bottom. We can estimate left ≈ 450 and right ≈ 650 from the first screenshot, but we still need the top and bottom values.

  2. Your viewport size: Go to Project Settings → Display → Window and tell us the Viewport Width and Viewport Height.

  3. Your camera’s Zoom: You previously mentioned (40, 40). Can you confirm that’s still the value being used?

  4. Confirm this is the active Camera2D: Since you’re calling MakeCurrent(), it probably is, but it’s worth checking that another Camera2D isn’t becoming current afterward.

Send those values and we should be able to fix the issue.

I don’t exactly know how to find the exact world coordinates,

but for 2, 3, and 4, The viewport size in width and height is : 1152 (width) & 648 (Height)
I can confirm that the camera’s zoom size is 40, 40, as I have tested this multiple times with this value (both when it is set by default and set to 40,40 in the code)
And I can confirm that the Camera2d is the current camera as I have it apart of the main starting scene as seen here.

I think the solution is to not make the limits to small for the viewport.
Oh.. and if you have planed on using pixel art in the future,
make the viewport size 360(High) 640(width) do to pixel scaling.

Edit: if you zoome in code do this one line before setting the limits.
Edit2: dont forget to mark as solution :slight_smile:

I understand it is a hassle to find the world coordinates, this isn’t the most intuitive feature to set up in Godot. But once you find them, your camera issues should be diminished.

One simple approach is to temporarily place four Node2Ds in your scene: one at the left, right, top, and bottom edges of the room. Then, select each one and look at its Transform → Position values in the Inspector.

Use the X values for LimitLeft and LimitRight.
Use the Y values for LimitTop and LimitBottom.

Once you’ve entered those values into your camera limits, everything should line up correctly. After that, you can safely delete the four temporary Node2Ds, because they were only there to help you measure the room’s world coordinates.

Edit: That’s the thing about camera limits: SpaghettiCoder and I can’t tell you the exact numbers because they’re unique to your room. The correct values come from measuring the boundaries of your world.

I checked on the rulers on the side and the top is a bit under 455 and the bottom is halfway under 635. as for the node methods I’ll try doing it based on the position, though Im a bit unsure of if it will actually work as I’ve had weird behavior happen based on wether or not a node’s position is based on another node’s global position or general position. I’ll still try though.

Just did that, and from what I see the limits appear to be based on the rulers above as when I do enter the Node2d transforms that are on the edges of the room when I set them as the limits in my debug version of the scene they go to a completely different area

In a way this was kind of why I was having trouble with the other methods of setting camera limits as its very hard to get a good understanding where the bounds of the area I want to confine the camera to is relative to GlobalPositioning terms when the positioning in this engine is so very tricky.

Since you’ve already found a method that works using the rulers, that’s perfectly fine, as long as you’re comfortable reading them accurately.

I also removed the Mathf.Clamp block because Camera2D already clamps itself to its configured limits every frame. Manually clamping the camera’s position may have been fighting the built-in behavior. Since I don’t know your room’s exact world coordinates, you may still need to fine-tune the limit values.

void Room2Camera()
{
    // Only run when the player entered from Entrance 1
    if (!GetNode<RoomBussFile>("/root/RoomBussFile").IsFromEnterance1)
        return;

    // Make this the active camera
    MakeCurrent();

    // Room bounds in global/world pixels
    LimitLeft   = 450;
    LimitTop    = 455;
    LimitRight  = 650;
    LimitBottom = 635;

    // Snap to the new framing instead of gliding from the previous position
    ResetSmoothing();
}

I don’t really have a method that works with the rulers I just have the data you wanted from me, I still don’t know how to fix it, and the code you gave me is just the sort of essentials of my other code besides the clamping, which still has the problem of the camera going to the corner.

typing this here as Sealstudios did respond to me its just that response somehow didn’t end up in the forum thread, they told me to insert this code for the limits so we could find their global position in order to further diagnose the problem

and my response to this was this:

"I tried this, and so far the position that got printed when I printed the values into the console was (Left)451,(Right)651,(Top)205,(Bottom)385

also as for other notes the Camera has gone to somewhere in the map when I input the code (as seen in the photo) which while it isnt in any way close to the player which is where I’d want it to be, at least it isn’t in that one corner or further anymore"

I found the solution to my problem! Turns out Sealstudios was onto something about the camera limits being way too small. In retrospect I think maybe I somehow mixed up some of the values based on the formatting of the limits I had in the code, though I swore I remembered it looking fine in the Editor. Regardless of that, I managed to double check and fix my Camera Limits by putting four Node2Ds in the corners of the area where I want my Camera limits to be, had them print their Global Positions, and then set the Limits to be that of the Global Positions Printed (the lowest x value for the left, highest x value for the right, highest y value for the bottom, and the lowest y value for the top.) Now the Camera limits work exactly how I want them to be and I am no longer having the issue of the camera screen getting stuck in a corner.

So in the case of the camera seemingly getting stuck without one knowing why make sure to double-check if the limits are properly set by referencing them to the Global Positions you want the bounds to be set to (by using markers to measure the positions)

Thank you all for your help!

Solutions are ment to give to the people who camed up with it.
Not just some random post.
It is kinda like a star sistem (for me).

Well the solution marker is not really meant to be some sort of likes system or anything its just supposed to say what solved the issue of the problem man. Thats why it puts the solution at the top when you mark it. You dont really go on help forums to get clout or anything or to be the most popular and well respected forum member, you just go on help forums to get/give help :V .

So why is one of the first things you see when you click on my profile the solutions?
It is ther to let people know if they can trust me and tho show some kind of skil and the willignes tho help.

But maybe i am wrong her?
Lets see what the moderators do. : )

Still thats just one of the many stats you can have on your profile, being the person who happens to solve the most problems isnt the one thing that shows your willingness to help, hell considering how these stats are tucked away on the user profile rather than being some sort of thing showed when you write in the forums, I doubt people are meant to actually care too much about that stuff when giving out solution marks, more so they just only care about wether the suggestion offered fixed the problem, so in a way its more like a job resume than some sort of popularity gauge. Even then these help forums are moreso designed to focus more on helping to solve the problem itself rather than the just people answering it, so I feel like looking at it from the angle of just getting the most likes and solution marks and instead of helping people solve the problems is just kinda looking at it wrong.

I do appreciate your attempts at helping me but if I just gave you a random solution notifier on a post that doesn’t have the actual solution that fixed my problem then all it will do is confuse people, as its not designed to be some sort of “likes” system at the end of the day. Idk thats all I have to say though, as my problem is done and solved and the forum reply rules clearly state that any additional talk on finished topic that aren’t expository in any way are unnecessary, so bye for now.

This is the solution to why the camara gets stuck.
I dont get the point on creating an extra post to give a solution mark to your own post,
rather then geting your first solution.
and i belive it is kinda of a rewarding sistem like the stars on github.

I didn’t know if that was the exact solution then and even then he didn’t really give an clear exact solution on what to do, just pointed out the problem, I don’t plan to disregard this guys help anytime soon (as I did point out his help in the post and I thanked everyone who helped in the thread), and I don’t intend to give myself a “free solution just for bragging rights” or anything as I don’t care about that, the only reason why I gave the solution to my own post is because I managed to find a way to fix the problem and wanted to give a clear example of what to do for anyone with the same problem that I had who managed to stumble onto this forum post. Please just drop the topic now man, its not related to the problem of the help post and in general is not that big of a deal. Please just move on.

Solution marks are primarily meant to be given to posts that resolved (or helped to resolve) the original problem, so that other users having the same problem in the future can easily identify the solution in the sea of replies.

It’s not always that simple, as some problems require more than one post to compile a full solution, and it is a subjective decision which post was most relevant.

Moreover, it’s perfectly fine to mark your own post as a solution, as long as it contains the actual solution. It is good practice to additionally give credit to whoever helped solve the problem in such cases, if applicable. I don’t see any issue with how this topic was marked as solved.

I will close this topic now, as the original problem is resolved and the following discussion veered off-topic. If you want to continue the discussion - feel free to use the DMs.