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

Im very new to Godot and GDScript so this might just be a mistake on my half but it seems that the Input feature is not working in a curtain function.

Here's my script :
extends Spatial

func _ready(): pass

func _on_Invisble_Collision_Door_Room_YOU_body_entered(body):
if body is KinematicBody and Input.is_action_just_pressed("interact"):
$anim1.play("DoorOpen")
pass

I have got rid of the imput part of the script Input.is_action_just_pressed("interact") and it works just fine with collisions but Input isn't working in the func.

BTW, Indents are there in the code.

Anyone has any help, it is very appreciated.
Joe.

in Engine by (16 points)

2 Answers

0 votes

For doors, I like to use getoverlappingbodies()
Try putting this in your function:

var bodies = get_overlapping_bodies()
for body in bodies: 
    if body.name == "KinematicBody": 
        if Input.is_action_pressed("interact"): 
            #anim1.play("DoorOpen")
by (14 points)

I don't completely understand but i tried to implement it anyway.
This is what i ended up with :

extends Spartial

func _ready():
    pass

func _process(delta):
    pass

func _on_Invisible_Collision_Door_Room_YOU_body_entered(body):
    var bodies = get_overlapping_bodies()
    for body in bodies:
        if body.name == KinematicBody:
            if Input.is_action_just_pressed("interact"):
                $anim1.play("DoorOpen")

That is the full script but it still doesn't work and once again i got rid of if Input.is_action_just_pressed("interact"): but this time getting rid of it doesn't help.

If you could, can you link me to a tutorial or a example project

Thanks, Joe

0 votes

´just_pressed´ (or Input in general) may never work while signals are processed, you need to check it on process and store in a variable until next process.

Another approach is to assign the door to the node that has the open option, remove it on body exit.
Process the input and activate the item that is being touched if there is any.

by (7,954 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] with your username.