This is the code I have for interacting with things, like opening doors.
var doorOpen : bool
var canOpenClose : bool
func _ready():
doorOpen = true
canOpenClose = true
func _process(delta):
#Gets if raycast is colliding and what with
if Global.raycastColliding == true:
var object = Global.raycastCollider
if object.get_parent().get_name() == "Doors":
var animPlayer = object.get_node("AnimationPlayer")
#Changes canOpenClose to allow doors to open or close again
if Input.is_action_just_pressed("left_click"):
canOpenClose = true
#Changes state of door between open and closed, keeps it from
#changing back with canOpenClose
if Input.is_action_just_released("left_click"):
if doorOpen == false and canOpenClose == true:
doorOpen = true
canOpenClose = false
if doorOpen == true and canOpenClose == true:
doorOpen = false
canOpenClose = false
#Plays the corresponding animation
if doorOpen == false and Input.is_action_just_pressed("left_click"):
animPlayer.play("Door_Open")
if doorOpen == true and Input.is_action_just_pressed("left_click"):
animPlayer.play_backwards("Door_Open")
To explain what's going on, if the object the raycast is interacting with is a child of the Doors node, it'll go through with the rest of the code. The doorOpen variable is whether the door is open or not, and the canOpenClose variable is used to make sure the state of doorOpen only changes once per interaction, otherwise doorOpen would go from false to true back to false all at once.
Is there anything in here that looks like it would be causing the issue? Let me know if you need more info.