This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
0 votes

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

Godot version Godot Engine v3.4.2.stable.official.45eaa2daf
in Engine by (17 points)

1 Answer

0 votes
Best answer

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 :) 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...

by (1,346 points)
selected by

"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.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.