Topic was automatically imported from the old Question2Answer platform.
Asked By
Lgdn
Hello
i have a game with a home
i’ve put a area2D in the home to detect if the character is in the home
if he was in the home we can show what is inside the home
else,if we aren’t in the how then we can watch what outside the home
Wipe out all of the code that you showed us from the Player script.
Instead of “on area entered/exited”, try using “on body entered” and “on body exited”.
Connect the body entered/exited signals to the scene script.
Once connected, try using .visible = true / .visible = false again, but I’m a little concerned about the get_node() part. If the wall node and the area2D node are both a part of the same scene, you can try doing $wall.visible = true and $wall.visible = false, or $wall.show() and $wall.hide()
Lastly, make sure the physical layering is correct. Go to Project Settings ->General->Layer Names->2d Physics. Rename Layer 1 to World and Layer 2 to Player.
Open the Inspector for the Area2D node, in Collision, Layer, click on the little … next to the grid, and only select World. Then click on … next to the Mask and only select Player.
For Player collision, set the opposite values. So in Layer, put Player, and in Mask put World.
That is the most basic way of detecting a player body and using signals accordingly.
See if it helps.
Alternatively, instead of the World Layer/Mask you can use another Layer (for example Layer 3) and rename it to something like Player Detector and set that instead of the World layer/mask for the Player and Area2D.
I did all the steps but it still doesn’t work
Lgdn | 2021-08-12 15:18
I made a little mistake in my previous answer. Try connecting both signals to the scene script, instead of Player or Area2D.
Here, try this project and use it as a template/reference: Upload Files | Free File Upload and Transfer Up To 10 GB