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

https://cdn.discordapp.com/attachments/749055989734703245/847586780802842654/unknown.png

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():
    set_process(false)

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

func _on_Area2D_body_entered(body):
    set_process(true)

func _on_Area2D_body_exited(body):
    set_process(false)

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 (170 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 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.