浏览代码

:beetle: Prevent game to crash when getting in while still getting out

Lock get out / in action during transition.

Note : move control stop at the end of getting out, so you can still
drive the vehicle until you are completely out.
DricomDragon 2 月之前
父节点
当前提交
878488b850
共有 1 个文件被更改,包括 24 次插入4 次删除
  1. 24 4
      godot/component/entity/walker/walker.gd

+ 24 - 4
godot/component/entity/walker/walker.gd

@@ -26,6 +26,7 @@ var target_character_direction := Vector3.ZERO # From command
 
 var _vehicle: SeatedVehicle = null
 var _can_get_in: bool = false
+var _in_transition: bool = false
 
 @onready var _vehicle_range: RayCast3D = $VehicleRange
 
@@ -127,6 +128,9 @@ func _on_get_in_action(commander: LocalInput) -> void:
 ## and get in to it
 ## and take the wheel !
 func _get_in_vehicle(commander: LocalInput) -> void:
+	if _in_transition:
+		return
+
 	var closest_vehicle: SeatedVehicle = _get_closest_vehicle()
 
 	if closest_vehicle == null:
@@ -142,17 +146,19 @@ func _get_in_vehicle(commander: LocalInput) -> void:
 
 ## Get out of the current vehicle
 func _get_out_vehicle() -> void:
-	_vehicle.get_out()
-	_start_getting_out()
-
+	if _in_transition:
+		return
+	_init_transition()
 
-func _start_getting_out() -> void:
 	var tween = create_tween()
 	tween.tween_property(self, "transform", _vehicle.get_door().get_transform(), board_seat_access_duration)
 	tween.tween_callback(_finish_getting_out)
 
 
 func _finish_getting_out() -> void:
+	_end_transition()
+
+	_vehicle.get_out()
 	remove_collision_exception_with(_vehicle)
 	reparent(_vehicle.get_parent())
 	_vehicle = null
@@ -189,6 +195,8 @@ func _get_closest_vehicle() -> SeatedVehicle:
 
 ## Move gently to a free seat from the nearest door
 func _move_to_seat(vehicule: SeatedVehicle) -> void:
+	_init_transition()
+
 	var tween: Tween = create_tween()
 
 	var door: Node3D = vehicule.get_closest_door(get_position())
@@ -198,3 +206,15 @@ func _move_to_seat(vehicule: SeatedVehicle) -> void:
 	var seat: Node3D = vehicule.get_free_seat()
 	tween.tween_property(self, "position", seat.get_position(), board_seat_access_duration)
 	tween.parallel().tween_property(self, "quaternion", seat.get_quaternion(), board_seat_access_duration)
+
+	tween.tween_callback(_end_transition)
+
+
+## Lock getting in / out while still doing it
+func _init_transition() -> void:
+	_in_transition = true
+
+
+## Allow walker to get in / out again
+func _end_transition() -> void:
+	_in_transition = false