Camera2D makes Area2D detection offset from the viewport

Godot Version

Godot v4.3.stable - macOS 14.6.1 - GLES3 (Compatibility)

Question

It seems that the camera position alters the area collision detection. I link the video because it’s easier to explain:
In the video debug collision shapes are correctly displayed and they seem to stay in position with their Node, however, the char can be placed only when released in the center of the viewport where the Area2d should be if the camera wouldn’t have moved



What I tried:

  • It’s not the camera movement that causes the bug. I tried to keep the camera still but offset its position in the editor, and the area detection remains in the center of the viewport, instead of being on the red square.
  • I tried not to use a Control for the CharUI and replaced the parent with the DropPointDetector node (I thought of strange behavior with the Control node)
  • One interesting thing: I added callbacks for ‘on_mouse_entered’ and ‘_on_area_entered’ on the DropDownArea (the red square). ‘on_mouse_entered’ is correctly detected in the square position, even when the camera moves, but ‘_on_area_entered’ remains detected only in the original position, not aligned with the square

Replying to my own post with the solution. Maybe someone with the same problem will end up on this.

Details

The problem was that the CanvasLayer would stay in position, even if the camera moved:
CanvasLayer → Follow Viewport → Enabled → check :white_check_mark:

Doing this, the CanvasLayer would follow the camera, and the area detection would work because the positions would match.

However, I don’t want to have CanvasLayer moving around with the camera, it should remain still in front of everything as UI would do.

The solution was to reparent the CharUI with the root, away from the CanvasLayer, when dragging, so it would match position with the area and detect collision correctly.

1 Like

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