|
@@ -7,11 +7,18 @@ const MINIMAL_CRASH_SPEED: float = 1.0 # m2/s2
|
|
|
var _current_commander: LocalInput = null
|
|
|
var _has_collided: bool = false
|
|
|
|
|
|
+@onready var _seat: Node3D = find_child("*Seat")
|
|
|
+@onready var _doors: Array = find_children("*Door", "Node3D") # Array[Node3D]
|
|
|
+
|
|
|
|
|
|
func _init() -> void:
|
|
|
body_shape_entered.connect(_on_body_shape_entered)
|
|
|
|
|
|
|
|
|
+func _ready() -> void:
|
|
|
+ assert(_doors.all(func(door): return door is Node3D))
|
|
|
+
|
|
|
+
|
|
|
## Make the vehicle responds to driver commands
|
|
|
func drive_with(commander: LocalInput) -> void:
|
|
|
commander.dir_changed.connect(_on_dir_changed)
|
|
@@ -51,19 +58,26 @@ func _crash_on(pos: Vector3) -> void:
|
|
|
get_parent_node_3d().add_child(crash_effect)
|
|
|
|
|
|
|
|
|
-## Need to be overridden to return an available seat
|
|
|
func get_free_seat() -> Node3D:
|
|
|
- return null
|
|
|
+ return _seat
|
|
|
|
|
|
|
|
|
-## Need to be overridden to return an arbitrary door
|
|
|
+## Can be overridden to return a specific door
|
|
|
func get_door() -> Node3D:
|
|
|
- return null
|
|
|
+ return _doors[0] as Node3D
|
|
|
|
|
|
|
|
|
-## Need to be overridden to return the nearest door from local position
|
|
|
func get_closest_door(from: Vector3) -> Node3D:
|
|
|
- return null
|
|
|
+ var distance = func distance_lambda(door: Node3D) -> float:
|
|
|
+ return (door.get_position() - from).length_squared()
|
|
|
+
|
|
|
+ var closest = func closest_lambda(previous_closest: Node3D, maybe_closest: Node3D) -> Node3D:
|
|
|
+ if distance.call(maybe_closest) < distance.call(previous_closest):
|
|
|
+ return maybe_closest
|
|
|
+ else:
|
|
|
+ return previous_closest
|
|
|
+
|
|
|
+ return _doors.reduce(closest)
|
|
|
|
|
|
|
|
|
## Need to be overridden to react to direction changed
|