Browse Source

:tada: Action prompt to show when a player can get in

Very useful for newcomers who wonders how to get in a vehicle.
DricomDragon 2 weeks ago
parent
commit
882e2efbcb

+ 16 - 2
godot/component/entity/walker/walker.gd

@@ -5,6 +5,7 @@ extends CharacterBody3D
 signal focus_required(me: Node3D)
 signal got_in
 signal got_out
+signal can_get_in(possible: bool)
 
 ## How fast the player moves in meters per second.
 @export var speed = 14
@@ -25,6 +26,7 @@ var target_character_direction := Vector3.ZERO # From command
 
 var _vehicle: Node3D = null
 var _seat: Node3D = null
+var _can_get_in: bool = false
 
 @onready var _vehicle_range: RayCast3D = $VehicleRange
 
@@ -47,11 +49,17 @@ func is_onboard() -> bool:
 	return _vehicle != null
 
 
+## Return true if the player can get in a vehicle
+func can_get_in_vehicle() -> bool:
+	return !is_onboard() and _get_closest_vehicle() != null
+
+
 func _physics_process(delta: float) -> void:
 	if is_onboard():
 		_get_on_driver_seat()
 	else:
 		_move_with_feet(delta)
+		_signal_when_can_get_in()
 
 
 func _move_with_feet(delta: float):
@@ -76,6 +84,14 @@ func _move_with_feet(delta: float):
 	move_and_slide()
 
 
+## Trigger only signal when ability is changed
+func _signal_when_can_get_in() -> void:
+	var can_get_in_now : bool = can_get_in_vehicle()
+	if _can_get_in != can_get_in_now:
+		can_get_in.emit(can_get_in_now)
+		_can_get_in = can_get_in_now
+
+
 func _get_on_driver_seat() -> void:
 	if _seat == null :
 		return
@@ -166,10 +182,8 @@ func _get_closest_vehicle() -> Node3D:
 		var node_within_range: Node3D = object_within_range as Node3D
 
 		if node_within_range.is_in_group("vehicle"):
-			print("Get in ", node_within_range)
 			return node_within_range
 
-	print("No vehicle found")
 	return null
 
 

+ 29 - 0
godot/component/ui/input_prompts/get_in/get_in_container.tscn

@@ -0,0 +1,29 @@
+[gd_scene load_steps=5 format=3 uid="uid://dl6fmkdlrcj53"]
+
+[ext_resource type="Texture2D" uid="uid://clcwaemf3uawa" path="res://addons/input_prompts/icons/xbox/y.png" id="1_l00e1"]
+[ext_resource type="Script" path="res://addons/input_prompts/action_prompt/action_prompt.gd" id="2_gfb15"]
+
+[sub_resource type="InputEventKey" id="InputEventKey_ffrfv"]
+device = -1
+physical_keycode = 4194309
+
+[sub_resource type="InputEventJoypadButton" id="InputEventJoypadButton_qub51"]
+device = -1
+button_index = 3
+
+[node name="GetInPromptContainer" type="HBoxContainer"]
+
+[node name="GetInLabel" type="Label" parent="."]
+layout_mode = 2
+theme_override_font_sizes/font_size = 34
+text = "Get in vehicle"
+
+[node name="GetInActionPrompt" type="TextureRect" parent="."]
+custom_minimum_size = Vector2(100, 100)
+layout_mode = 2
+texture = ExtResource("1_l00e1")
+stretch_mode = 5
+script = ExtResource("2_gfb15")
+action = "get_in"
+icon = 0
+events = Array[InputEvent]([SubResource("InputEventKey_ffrfv"), SubResource("InputEventJoypadButton_qub51")])

+ 8 - 1
godot/run/levels/infinite_level.tscn

@@ -1,4 +1,4 @@
-[gd_scene load_steps=30 format=3 uid="uid://7ivipmwaw24t"]
+[gd_scene load_steps=31 format=3 uid="uid://7ivipmwaw24t"]
 
 [ext_resource type="Texture2D" uid="uid://cgwafs6ukpm7y" path="res://component/entity/ground/ground051.jpg" id="1_3ytcp"]
 [ext_resource type="Script" path="res://run/levels/camera_tracker.gd" id="1_qdm47"]
@@ -21,6 +21,7 @@
 [ext_resource type="PackedScene" uid="uid://c68bdcjpdm1y2" path="res://component/ui/pause/pause_menu.tscn" id="16_orqqe"]
 [ext_resource type="PackedScene" uid="uid://bmgwhm6ejsden" path="res://component/ui/victory/victory_menu.tscn" id="17_1u7wg"]
 [ext_resource type="PackedScene" uid="uid://d6a3dml2i2qm" path="res://component/ui/input_prompts/jump/jump_container.tscn" id="17_6r3c0"]
+[ext_resource type="PackedScene" uid="uid://dl6fmkdlrcj53" path="res://component/ui/input_prompts/get_in/get_in_container.tscn" id="18_bejgn"]
 [ext_resource type="Script" path="res://flow/signal_wire/space_limit.gd" id="19_3qyrt"]
 
 [sub_resource type="BoxShape3D" id="BoxShape3D_ctk0t"]
@@ -419,6 +420,10 @@ layout_mode = 2
 [node name="JumpPromptContainer" parent="UI/InputPromptsCenter/InputPromptsCollection" instance=ExtResource("17_6r3c0")]
 layout_mode = 2
 
+[node name="GetInPromptContainer" parent="UI/InputPromptsCenter/InputPromptsCollection" instance=ExtResource("18_bejgn")]
+visible = false
+layout_mode = 2
+
 [node name="TitleScreen" parent="UI" instance=ExtResource("13_2xijd")]
 
 [node name="PauseMenu" parent="UI" instance=ExtResource("16_orqqe")]
@@ -457,8 +462,10 @@ script = ExtResource("19_3qyrt")
 transform = Transform3D(-1, 0, 0, 0, -1, 0, 0, 0, -1, 0, 0, 0)
 shape = SubResource("WorldBoundaryShape3D_cdiox")
 
+[connection signal="can_get_in" from="MainWalker" to="UI/InputPromptsCenter/InputPromptsCollection/GetInPromptContainer" method="set_visible"]
 [connection signal="focus_required" from="MainWalker" to="CameraTracker" method="_on_focus_required"]
 [connection signal="got_in" from="MainWalker" to="MusicPlayer" method="_on_driver_got_in"]
+[connection signal="got_in" from="MainWalker" to="UI/InputPromptsCenter/InputPromptsCollection/GetInPromptContainer" method="hide"]
 [connection signal="got_out" from="MainWalker" to="MusicPlayer" method="_on_driver_got_out"]
 [connection signal="dir_changed" from="MainWalker/Control" to="MainWalker" method="_on_dir_changed"]
 [connection signal="get_in_action" from="MainWalker/Control" to="MainWalker" method="_on_get_in_action"]