|
@@ -5,12 +5,14 @@ const CRASH_EFFECT: Resource = preload("res://effect/crash/crash.tscn")
|
|
|
const MINIMAL_CRASH_SPEED: float = 1.0 # m2/s2
|
|
|
|
|
|
var _current_commander: LocalInput = null
|
|
|
+var _current_driver: Walker
|
|
|
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)
|
|
|
|
|
@@ -19,6 +21,11 @@ func _ready() -> void:
|
|
|
assert(_doors.all(func(door): return door is Node3D))
|
|
|
|
|
|
|
|
|
+## Signal a new driver
|
|
|
+func become_driven_by(driver: Walker) -> void:
|
|
|
+ _current_driver = driver
|
|
|
+
|
|
|
+
|
|
|
## Make the vehicle responds to driver commands
|
|
|
func drive_with(commander: LocalInput) -> void:
|
|
|
commander.dir_changed.connect(_on_dir_changed)
|
|
@@ -34,6 +41,7 @@ func get_out() -> void:
|
|
|
_current_commander.stop_action.disconnect(_on_stop_action)
|
|
|
_current_commander.analog_action.disconnect(_on_analog_action)
|
|
|
_current_commander = null
|
|
|
+ _current_driver = null
|
|
|
|
|
|
|
|
|
func _integrate_forces(state: PhysicsDirectBodyState3D) -> void:
|
|
@@ -80,6 +88,11 @@ func get_closest_door(from: Vector3) -> Node3D:
|
|
|
return _doors.reduce(closest)
|
|
|
|
|
|
|
|
|
+## Return current walker who is driving the vehicle, null if none
|
|
|
+func get_current_driver() -> Walker:
|
|
|
+ return _current_driver
|
|
|
+
|
|
|
+
|
|
|
## Need to be overridden to react to direction changed
|
|
|
func _on_dir_changed(_dir: Vector2) -> void:
|
|
|
pass
|
|
@@ -90,7 +103,7 @@ func _on_main_action(_pressed: bool) -> void:
|
|
|
pass
|
|
|
|
|
|
|
|
|
-## Need to be overridden to react to main action
|
|
|
+## Need to be overridden to react to stop action
|
|
|
func _on_stop_action(_pressed: bool) -> void:
|
|
|
pass
|
|
|
|