Camera2D Locking Player Movement

Godot Version

v4.2.2.stable.mono.official [15073afe3]

Question

Hi Godot Community, nice to meet you all!

I have encountered a problem while trying to add a camera that follows the player. From some forum crawling I found that I should be able to just add a Camera2D node as a child node to the CharacterBody2D of the player to get the camera to follow the player model properly, but when I add the node and test the game, the player is unable to move from it’s starting position. The game is still detecting user input and the sprite animations change as I change input direction, but the player cannot move from their starting position.

I’ve done some Google searching and scrolling the docs, but I haven’t found any mentions on the forums of anyone having similar problems. For what it’s worth, it is also shifting the TextureRect far down and to the right instead of centered in the viewport. When I remove the Camera2D, these issues go away.

Any ideas as to what I might be missing?

Can share code in pastebin if that’s better.

I determined at least it does not appear to be related to collision (as the player is still locked in place with the CollisionShape2D disabled) or the clamp() funtion (as commenting that out does not fix the problem either). Going to continue digging.

Actually just had a bit of a breakthrough. If I turn off the TestRoom scene and show the ColorRect instead, it works fine. So the issue seems to be with the TileMap somehow

Ok I also figured out that when I have a Camera2D node, my TextureRect which makes up the Title screen will move with player input. Not sure why having a Camera node would make two unrelated nodes player controlled

I figured it out! It looks like the TileMap needs to have CanvasLayer > Follow Viewport > Enabled Checked off, otherwise it will follow the camera rather than stay in place. Hope this helps someone else down the line.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.