0 votes

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 onArea2Dareaexited(area):
get_node(wall).visible = true

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

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

https://we.tl/t-8zCOsutUcp

Godot version 3.3.2
in Engine by (25 points)

2 Answers

0 votes

So on the first line it says extends RigidBody2D.

by (50 points)

yes,has u can see

it needs to say extends Area2D

bruh

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

well for the player you need to use a kinamaticbody2d.

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

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

and the link just takes me to a random website

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

Yes I do have discord.

+2 votes

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.

by (33 points)
edited by

I did all the steps but it still doesn't work

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: https://easyupload.io/bz5xi0

Hopefully it helps.

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 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 webmaster@godotengine.org with your username.