Godot Version
4.3 Stable
Question
Hi. I am creating a game and within this game there is a door mechanic, the point is that the door closes automatically after some time after the player has left the door area. To do this, I used Area3D to track when the player leaves the zone. After leaving, you can start the timer to close automatically.
I think I did everything right. However, for some reason gdscript thinks that using @export, var name: bool = false is an error. I don’t understand what happened here…
Line 8:Unexpected" Identifier " in class body.
extends Node3D
@export var close_delay: float = 2.0
@export var open_angle: float = 90.0
@export var open_speed: float = 2.0
var is_open: bool = false
var player_in_area = false
onready var hinge_joint: HingeJoint3D = $HingeJoint3D
func _ready() -> void:
hinge_joint.target_rotation = 0.0
hinge_joint.motor_enabled = true
func _on_TriggerArea_body_entered(body):
if body.name == "Player":
player_in_area = true
is_open = true
open_door()
func _on_TriggerArea_body_exited(body):
if body.name == "Player":
player_in_area = false
await get_tree().create_timer(close_delay).timeout
if not player_in_area:
is_open = false
close_door()
func open_door():
hinge_joint.target_rotation = deg_to_rad(open_angle) # Переводим угол в радианы
animate_door()
func close_door():
hinge_joint.target_rotation = 0.0 # Возвращаем дверь в начальное положение
animate_door()
func animate_door():
while hinge_joint.joint_rotation < hinge_joint.target_rotation - 0.01 or hinge_joint.joint_rotation > hinge_joint.target_rotation + 0.01:
var difference = hinge_joint.target_rotation - hinge_joint.joint_rotation
hinge_joint.motor_velocity = sign(difference) * open_speed
await get_tree().process_frame
hinge_joint.motor_velocity = 0.0