Collision detection issues persisting in different locations

This is regarding ToolKit mode and top-down game creation.

This continues from the discussion in the following link:

https://guild.rpgmakerofficial.com/t/topic/3485?u=m_u

There are Object A (with ObjectMountTarget), Object B, Object C, and Object D (placed on the map). (Everything except the player and D is an Area2DGameObject.)

• Create a menu scene and place Object A.
• Press a key to display the menu, which spawns Object B into Object A’s ObjectMountTarget.
• After spawning Object B, spawn Object C into Object A’s ObjectMountTarget at B’s connection point, and make it a child of B.
• Move the player object to contact Object D, causing Object D to disappear. Then, respawn Object D into Object A’s ObjectMountTarget and make it a child of Object C.

Visually, this works as intended, but for some reason, Object D’s collision shape (wall) remains near the origin.

It’s possible that B or C also have colliders near the origin, but since they are lightweight objects, they might just not be interfering with the player. I have the “Show debug collision shapes” option enabled, but I can’t see the collider for Object D near the origin either…

movie_002

This might be coming from Godot itself. The menu is drawn on a UI layer (a CanvasLayer), but a CanvasLayer doesn’t get its own physics world, so every collision inside the menu still exists in the same physics world as your map.

The collision also uses the item’s position inside the menu as if it were a map position. So D’s wall lands near the map’s origin, offset by however far the item is from the top left of the screen. That could explain why the player gets pushed up when you drag the item up in your gif. I’m wondering if Visible Collision Shapes is drawing D’s shape inside the menu with the item instead, which would be why you can’t see anything at the origin.

B and C are probably sitting at the origin too, but as Area2DGameObjects they don’t block the player.

What if you made a separate Area2DGameObject version of D just for the menu, the same way B and C are, and generated that one when D is picked up? The regular D with its wall can stay on the map.

Thank you for your reply!

Regarding the explanation you provided:

  1. The actual wall is near the origin, and only the wall shape is drawn in the menu.

  2. Collision detection for the wall is created both near the origin and in the menu.

Which one is it? Or is it neither?

I’m a bit confused :sweat_smile:

If it’s #1, when dragging the icon in the menu, it seems like it wouldn’t be draggable because the condition requires the mouse cursor to be over the wall.

If it’s #2, I’ve configured the settings to disable wall collision detection during dragging, but when I disable that condition and drag to the player, no contact was detected with the player.

Can you clarify this point with your previous explanation?

I think it’s closer to #1. There’s only one wall, and its coordinates are the same as the icon’s coordinates inside the menu.

The mouse and the player read those coordinates differently. From what I’ve found, Godot checks the mouse against an object in the menu using the menu’s own screen coordinates, so the cursor still lines up with the icon and the drag works. The player is on the map, so it reads those same coordinates as a map position, which puts the wall near the origin.

That could also explain your second test. When you drag the icon onto the player on screen, the real wall is moving around near the origin, so it never touches the player.

1 Like

So you’re saying this strange phenomenon is due to Godot’s specifications?

If that’s the case, it seems difficult when trying to generate an arbitrary number of objects at arbitrary locations on the base layer, based on what exists in the menu scene, since the coordinates are different.

Does this mean that the menu scene was not designed with such scenarios in mind?

That said, it can’t be helped if it’s due to the specifications of Godot, the underlying engine…

Thank you very much for all your research!