Possible bug: Area2D and collision shape detection position in a canvas layer

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By litelo

I have a requirement in my touch enabled game where I need to move the camera by dragging the mouse to scroll through the level. I also have elements in my game that can be placed by clicking on the screen and removed by clicking and dragging them to a trash can. I am using Area2D with a sprite for the trash can and using the area_entered signal to detect the element to be deleted. I need the trashcan to remain in a corner of the screen even when the camera is being moved. For this, I have used a canvas layer with a control node as its child.

Nodes hierarchy

The Control node is to position the Area2D inside its FullRect.

Now the arrangement seems to work perfectly and the trash area is visibly stationery on the screen when camera is dragged around.

But when the camera is dragged away from its initial position, the Area2D’s detection area is fixed at a global position and does not move along with the Area2D and its sprite. So now, when the camera is dragged to the right, the trash’s actual detection area is to the left of where the sprite is. Looks like the detection area is fixed at a global position and not moving along with its parent.
I have also checked the collision shape using “visible collision shapes” in debug mode and it appears to be moving along with the Area2D.

Is anyone aware of this buggy behaviour and can provide any suggestions on it?

No dragging

After camera dragged

:bust_in_silhouette: Reply From: rossunger

Have you tried making the area 2d a child of the sprite and testing that?

Also, any chance you accidentally have some sort of physics applied to the area2d? there’s a physics override section in the inspector that could cause weird behavior

I find the interaction between Control nodes and 2D nodes isn’t always straightforward, and I can’t exactly figure out what it is.

A simple alternative, have you tried the remote_transform node? it’s pretty handy for this kinda thing :slight_smile: you could use it with the camera and it’ll move the trash node for you, so you don’t have to use canvas layer and all that…

“Have you tried making the area 2d a child of the sprite and testing that?”
I tried that but no change in behaviour. I also checked for any physics overrides but I did not find anything out of the ordinary there

I too gave up on the Control node and canvas layer and started working on continuously changing the global position of the trash area using the camera’s viewport_rect and position inside the _process() method.

The remote_transform node is new to me. I tried using it and it looks very promising. It does need some further work to work with different aspect ratios but I think that can be managed through script.

The takeaway form all this your point that control and 2D nodes do not go together well. So I will be using these alternatives.

litelo | 2022-02-06 16:32