0 votes

I'm trying to get it so that when and area2d enters the collision shape AND the If Input is pressed then this happens do you know how to do that


Godot version 3.3.1
in Engine by (15 points)

1 Answer

0 votes

Not sure if this is the best/efficient way of doing this but you could use the _process() function. Any code in the function is executed every frame and you can enable or disable it using set_process().

The code could look something similar to this:

func _ready():

func _process(delta):
    if Input.is_action_just_pressed("next"):
        # Do stuff

func _on_Area2D_body_entered(body):

func _on_Area2D_body_exited(body):

Note that when you override _process() in your code, processing gets enabled automatically, so if you want the object NOT to start processing right off the bat (AKA when it gets created), you should disable it in the _ready function.
So we disable _process() in the beginning. When the body enters the shape, we enable _process and listen for input. When the body leaves, we stop _process().

by (180 points)
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]ine.org with your username.