Hello,
I’m new to Godot and trying to make a 3d game. I have a main scene in which I import child scenes as objects.
The child scene in question is a door. I have a script in that scene that detects if the player is inside an aera3d and, if so, play an opening animation if the user click on the right mouse button.
It works well but if I add multiple door child scenes to the main scene, when the user click all doors open. I think it has to to do with the make unique parameter but I haven’t been able to make it work.
Here is my script:
extends Node3D
var player_infront := false
var player_present := false
var door_closed := true
@export var locked: bool = false
var from_end: bool = false
func _input(event: InputEvent) -> void:
if Input.is_action_just_pressed('primary'):
if player_present and !$AnimationPlayer.is_playing():
if door_closed and !locked:
door_closed = false
if player_infront:
$AnimationPlayer.play('Ouverture')
else:
$AnimationPlayer.play('Ouverture_2')
func _on_detection_zone_body_entered(body: Node3D) -> void:
player_present = true
player_infront = true
func _on_detection_zone_body_exited(body: Node3D) -> void:
player_present = false
player_infront = true
func _on_leave_zone_body_exited(body: Node3D) -> void:
player_present = false
if !door_closed:
door_closed = true
if $AnimationPlayer.is_playing():
await $AnimationPlayer.animation_finished
if player_infront:
$AnimationPlayer.play('Fermeture')
else:
$AnimationPlayer.play('Fermeture_2')
func _on_area_3d_body_entered(body: Node3D) -> void:
player_present = true
player_infront = false
func _on_area_3d_body_exited(body: Node3D) -> void:
player_present = false
player_infront = false
And the child scene:
Thank you for your help!
