This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
0 votes

Hello all, I want to interact with some objects in this scene, but dont know how to do that. Can someone tell me what I need to do?
enter image description here

in Engine by (177 points)

1 Answer

+1 vote
Best answer

You need to place Area2D nodes on all the objects you wish to interact with. Then, when the character enters those areas, a signal is triggered letting Godot know that a particular area has been entered. You can combine Area2D signals with other code too. For example, you can have a door open whenever the character is within the door area AND a key is pressed at the same time.

by (1,892 points)
selected by

Question: how do I implement this?I suppose I made a zone that the player enters, but when the key is pressed when the player is in the zone, nothing happens.My code:
extends Area

const CLOSED = 0
const OPEN = 1

var state = CLOSED

func ondoorpostanddoorareaentered(area):
if == "Playerarea" and Input.isactionjustpressed("uiE"):
if state == CLOSED:
state = OPEN
state = CLOSED

Sorry for the late reply!

I suppose that using the area entered signal alone will not do the trick in your case, because it is only good for when you want to trigger actions immediately after the signal is emiited. What you might want to try instead is create a bool variable (let's name it in_door_area for clarity's sake), then have it set to true when the area_entered signal is emitted and have it set to false when the area_exited signal is emitted. Then you just check whether the in_door_area is true or false AND a certain key is pressed. I hope this 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 Frequently asked questions and 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 [email protected] with your username.