Add manual reset option

soundtrack
Ensar Sarajčić 2021-11-20 17:44:35 +01:00
parent cc22ddb37b
commit 1850d12fe7
5 changed files with 20 additions and 14 deletions

View File

@ -107,6 +107,12 @@ gear_down={
, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":4,"pressure":0.0,"pressed":false,"script":null)
]
}
reset_vehicle={
"deadzone": 0.5,
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":82,"physical_scancode":0,"unicode":0,"echo":false,"script":null)
, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":3,"pressure":0.0,"pressed":false,"script":null)
]
}
[physics]

View File

@ -6,17 +6,17 @@ const CAMERA = preload("res://player/camera.tscn")
var player_node: Node
var gui: Node
onready var spawn_point = $PlayerSpawnLocation
onready var track = $Track
func _ready() -> void:
player_node.global_transform = spawn_point.global_transform
reset_player_to(track.get_last_checkpoint(), player_node)
add_child(player_node)
add_child(gui)
var player_camera = CAMERA.instance()
player_camera.global_transform = spawn_point.global_transform
player_camera.global_transform.origin -= spawn_point.global_transform.basis.z * 1000
player_camera.global_transform = player_node.global_transform.translated(
-player_node.global_transform.basis.z * 100
)
player_camera.follow_target_path = player_node.get_path()
add_child(player_camera)
@ -36,6 +36,11 @@ func reset_player_to(node_to_reset_to: Node, player_node: BuggedVehicle) -> void
player_node.reset_transform.origin += node_to_reset_to.global_transform.basis.y * 5
func _process(_delta: float) -> void:
if Input.is_action_just_released("reset_vehicle"):
reset_player_to(track.get_last_checkpoint(), player_node)
func _on_ResetArea_body_entered(body: Node) -> void:
if body.get_groups().has("car"):
reset_player_to(track.get_last_checkpoint(), body)

View File

@ -69,8 +69,6 @@ margin_bottom = 143.0
custom_fonts/font = SubResource( 2 )
text = "Exit to main menu"
[node name="PlayerSpawnLocation" type="Position3D" parent="."]
[node name="Track" parent="." instance=ExtResource( 6 )]
[connection signal="pressed" from="PauseMenu/MarginContainer/VSplitContainer/VBoxContainer/ContinueButton" to="PauseMenu" method="_on_ContinueButton_pressed"]

View File

@ -81,14 +81,11 @@ extents = Vector3( 226.72, 25.6138, 197.933 )
[node name="Spatial" instance=ExtResource( 1 )]
[node name="PlayerSpawnLocation" parent="." index="1"]
transform = Transform( -0.440065, 0, 0.897966, 0, 1, 0, -0.897966, 0, -0.440065, -28.0465, 52.1483, 87.0188 )
[node name="Track" parent="." index="2"]
[node name="Track" parent="." index="1"]
track_path = NodePath("../Path")
checkpoint_count = 30
[node name="Path" type="Path" parent="." index="3"]
[node name="Path" type="Path" parent="." index="2"]
curve = SubResource( 4 )
[node name="Track" type="CSGPolygon" parent="Path" index="0"]
@ -121,12 +118,12 @@ path_u_distance = 1.0
path_joined = true
material = SubResource( 7 )
[node name="Background" type="MeshInstance" parent="." index="4"]
[node name="Background" type="MeshInstance" parent="." index="3"]
transform = Transform( 224.434, 0, 0, 0, 224.434, 0, 0, 0, 224.434, 0, 0, 0 )
mesh = SubResource( 3 )
material/0 = null
[node name="ResetArea" type="Area" parent="." index="5"]
[node name="ResetArea" type="Area" parent="." index="4"]
[node name="CollisionShape" type="CollisionShape" parent="ResetArea" index="0"]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -106.576, 0 )

View File

@ -29,7 +29,7 @@ func get_last_checkpoint() -> Node:
func _ready() -> void:
start_time = OS.get_ticks_msec()
var length = path.curve.get_baked_length()
var section_size = 1.0 * length / checkpoint_count
var section_size = 1 * length / checkpoint_count
var section = 0.0
for _checkpoint_number in range(checkpoint_count):
var new_checkpoint: Area = Area.new()