body_entered triggered at viewport position

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

Hello,

I encounter a small problem.
I’m trying to learn Godot by doing a small 2D RTS. One of the feature is to be able to place a element in the world if there is no object below.

Expected:
Moving a “building” above a “rock” should add a red box to the building to indicate it’s not possible to drop it

If the camera is a its initial position, everything works fine:
enter image description here

But if the camera change its position, the event doesn’t trigger at the “rock” position:
enter image description here

It’s like, the body is bind to the viewport, I’m not sure if I miss something here or if all my code is wrong but I would like to habe some help.

Here is the code if you want to take a look: https://github.com/hyoa/gidobuild_godot
Don’t mind the anarchy in the structure of my project :frowning:

:bust_in_silhouette: Reply From: Zylann

I think this happens because you instanced dragged house under your UI layer canvas layer, which IS pinned to the viewport. You should instance the house under the world so that it will be rendered at correct position and collision checks will line up.

Thanks ! it was indeed that.

hyoa | 2019-09-07 13:40