Why area2d doesn't work ?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: 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

but that doesn’t work
how can i fix this ?

code :
extends RigidBody2D

export var wall : NodePath

func _on_Area2D_area_exited(area):
get_node(wall).visible = true

func _on_Area2D_area_entered(area):
get_node(wall).visible = false

some images and videos to understand what i whant to do :

:bust_in_silhouette: Reply From: toivocat

So on the first line it says extends RigidBody2D.

yes,has u can see

Lgdn | 2021-07-25 21:23

it needs to say extends Area2D

toivocat | 2021-07-25 21:24

bruh

this is the code of the character(the body of the character)

Lgdn | 2021-07-25 21:31

well for the player you need to use a kinamaticbody2d.

toivocat | 2021-07-25 23:55

THE BODY NO THE CHARACTER,IT’S A RAGDOLL SO IT’S A RIGIDBODY ! uh sorry

Lgdn | 2021-07-26 09:52

Ok sorry then I don’t know why that’s weird. Try redownloading Godot

toivocat | 2021-07-26 12:21

and the link just takes me to a random website

toivocat | 2021-07-26 12:22

it takes me here: WeTransfer - Send Large Files & Share Photos Online - Up to 2GB Free

toivocat | 2021-07-26 12:25

this what i whant to do
download the file and open the zip then open the images and video
do u have disscord ? it’s ezier to chat

Lgdn | 2021-07-26 14:58

Yes I do have discord.

toivocat | 2021-07-26 22:10

:bust_in_silhouette: Reply From: haha-lolcat1

Try a more basic way.

  1. Wipe out all of the code that you showed us from the Player script.
  2. Instead of “on area entered/exited”, try using “on body entered” and “on body exited”.
  3. Connect the body entered/exited signals to the scene script.
  4. 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()
  5. 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.
  6. 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.
  7. 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

Hopefully it helps.

haha-lolcat1 | 2021-08-12 15:58