From cc22ddb37bcf69561ebbb08fe0bcbb859526c214 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ensar=20Saraj=C4=8Di=C4=87?= Date: Sat, 20 Nov 2021 17:34:08 +0100 Subject: [PATCH] Fix vehicle reset logic --- scenes/base_track_level.gd | 9 +++++++-- vehicles/vehicle.gd | 2 ++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/scenes/base_track_level.gd b/scenes/base_track_level.gd index f6c0c5c..76683d4 100644 --- a/scenes/base_track_level.gd +++ b/scenes/base_track_level.gd @@ -27,8 +27,13 @@ func spawn_player(player_node: Node, gui: Node) -> void: func reset_player_to(node_to_reset_to: Node, player_node: BuggedVehicle) -> void: - player_node.reset_transform = node_to_reset_to.global_transform - player_node.reset_transform.origin += node_to_reset_to.global_transform.basis.y * 15 + player_node.reset_transform = node_to_reset_to.global_transform.looking_at( + node_to_reset_to.global_transform.translated( + node_to_reset_to.global_transform.basis.z + ).origin, + node_to_reset_to.global_transform.basis.y + ) + player_node.reset_transform.origin += node_to_reset_to.global_transform.basis.y * 5 func _on_ResetArea_body_entered(body: Node) -> void: diff --git a/vehicles/vehicle.gd b/vehicles/vehicle.gd index e9ed7f8..555a564 100644 --- a/vehicles/vehicle.gd +++ b/vehicles/vehicle.gd @@ -71,6 +71,8 @@ func _ready(): func _integrate_forces(state: PhysicsDirectBodyState) -> void: if reset_transform != Transform.IDENTITY: state.set_transform(reset_transform) + state.linear_velocity = Vector3.ZERO + state.angular_velocity = Vector3.ZERO reset_transform = Transform.IDENTITY