2021-11-18 20:07:42 +00:00
|
|
|
class_name BaseTrackLevel
|
2021-11-12 23:03:35 +00:00
|
|
|
extends Spatial
|
|
|
|
|
2021-11-18 23:43:19 +00:00
|
|
|
const CAMERA = preload("res://player/camera.tscn")
|
2021-11-18 23:36:05 +00:00
|
|
|
|
2021-11-12 23:03:35 +00:00
|
|
|
var player_node: Node
|
2021-11-13 22:55:18 +00:00
|
|
|
var gui: Node
|
2021-11-12 23:03:35 +00:00
|
|
|
|
2021-11-18 23:36:05 +00:00
|
|
|
onready var track = $Track
|
|
|
|
|
2021-11-18 23:08:21 +00:00
|
|
|
|
2021-11-12 23:03:35 +00:00
|
|
|
func _ready() -> void:
|
2021-11-20 17:46:23 +00:00
|
|
|
reset_player_to(track.get_furthest_checkpoint(), player_node)
|
2021-11-12 23:03:35 +00:00
|
|
|
add_child(player_node)
|
2021-11-13 22:55:18 +00:00
|
|
|
add_child(gui)
|
2021-11-18 23:36:05 +00:00
|
|
|
var player_camera = CAMERA.instance()
|
2021-11-20 16:44:35 +00:00
|
|
|
player_camera.global_transform = player_node.global_transform.translated(
|
|
|
|
-player_node.global_transform.basis.z * 100
|
|
|
|
)
|
2021-11-12 23:03:35 +00:00
|
|
|
player_camera.follow_target_path = player_node.get_path()
|
|
|
|
add_child(player_camera)
|
|
|
|
|
2021-11-18 23:08:21 +00:00
|
|
|
|
2021-11-13 22:55:18 +00:00
|
|
|
func spawn_player(player_node: Node, gui: Node) -> void:
|
2021-11-12 23:03:35 +00:00
|
|
|
self.player_node = player_node
|
2021-11-13 22:55:18 +00:00
|
|
|
self.gui = gui
|
2021-11-18 23:08:21 +00:00
|
|
|
|
|
|
|
|
|
|
|
func reset_player_to(node_to_reset_to: Node, player_node: BuggedVehicle) -> void:
|
2021-11-20 16:34:08 +00:00
|
|
|
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
|
|
|
|
)
|
2021-11-20 17:43:32 +00:00
|
|
|
player_node.reset_transform.origin += node_to_reset_to.global_transform.basis.y * 3
|
2021-11-18 23:08:21 +00:00
|
|
|
|
|
|
|
|
2021-11-20 16:44:35 +00:00
|
|
|
func _process(_delta: float) -> void:
|
|
|
|
if Input.is_action_just_released("reset_vehicle"):
|
2021-11-20 17:46:23 +00:00
|
|
|
reset_player_to(track.get_furthest_checkpoint(), player_node)
|
2021-11-20 16:44:35 +00:00
|
|
|
|
|
|
|
|
2021-11-18 23:08:21 +00:00
|
|
|
func _on_ResetArea_body_entered(body: Node) -> void:
|
|
|
|
if body.get_groups().has("car"):
|
2021-11-20 17:46:23 +00:00
|
|
|
reset_player_to(track.get_furthest_checkpoint(), body)
|