From 361e51d7149aca9c60dd1d3998c7b9311342082d Mon Sep 17 00:00:00 2001 From: Rob Kelly Date: Tue, 12 Nov 2024 11:40:15 -0700 Subject: [PATCH] Flag marker shows distance to goal --- levels/debug_level/debug_level.tscn | 2 +- src/props/flag/flag.gd | 20 ++++++++++++++++++++ src/props/{ => flag}/flag.tscn | 26 +++++++++++++++++++++++++- 3 files changed, 46 insertions(+), 2 deletions(-) create mode 100644 src/props/flag/flag.gd rename src/props/{ => flag}/flag.tscn (69%) diff --git a/levels/debug_level/debug_level.tscn b/levels/debug_level/debug_level.tscn index beeea4c..f62f429 100644 --- a/levels/debug_level/debug_level.tscn +++ b/levels/debug_level/debug_level.tscn @@ -13,7 +13,7 @@ [ext_resource type="PackedScene" uid="uid://dagh38vap4t1d" path="res://src/scenery/city/concrete_building_1.tscn" id="10_lf15j"] [ext_resource type="PackedScene" uid="uid://cjubxs7peir5k" path="res://src/scenery/city/kana_signboard.tscn" id="11_evxup"] [ext_resource type="PackedScene" uid="uid://di7aql54lksn7" path="res://src/scenery/trees/palm_tree/palm_tree.tscn" id="12_sswxf"] -[ext_resource type="PackedScene" uid="uid://c7l58wuuahn7w" path="res://src/props/flag.tscn" id="13_6jtao"] +[ext_resource type="PackedScene" uid="uid://c7l58wuuahn7w" path="res://src/props/flag/flag.tscn" id="13_6jtao"] [ext_resource type="Texture2D" uid="uid://dj60e8ri2fco" path="res://assets/models/scenery/city/concrete_building_1/concrete_building_1.png" id="14_y7s2h"] [sub_resource type="FastNoiseLite" id="FastNoiseLite_rpgb7"] diff --git a/src/props/flag/flag.gd b/src/props/flag/flag.gd new file mode 100644 index 0000000..7a132ee --- /dev/null +++ b/src/props/flag/flag.gd @@ -0,0 +1,20 @@ +@tool +extends Node3D + +@export var show_distance: bool: + set(value): + if distance_label: + distance_label.visible = value + get: + return distance_label.visible +@onready var distance_label: Label3D = %DistanceLabel + + +func _process(_delta: float) -> void: + if show_distance: + var viewport := get_viewport() + if viewport: + var camera := viewport.get_camera_3d() + if camera: + var distance := int(global_position.distance_to(camera.global_position)) + distance_label.text = "Goal!\n%d m" % distance diff --git a/src/props/flag.tscn b/src/props/flag/flag.tscn similarity index 69% rename from src/props/flag.tscn rename to src/props/flag/flag.tscn index 45a9ef8..3d95cda 100644 --- a/src/props/flag.tscn +++ b/src/props/flag/flag.tscn @@ -1,11 +1,35 @@ -[gd_scene load_steps=3 format=3 uid="uid://c7l58wuuahn7w"] +[gd_scene load_steps=5 format=3 uid="uid://c7l58wuuahn7w"] [ext_resource type="PackedScene" uid="uid://dqj60gh364mn5" path="res://assets/models/course/flag/flag.gltf" id="1_ona6u"] +[ext_resource type="FontFile" uid="uid://dsa0oh7c0h4pu" path="res://assets/fonts/Racing_Sans_One/RacingSansOne-Regular.ttf" id="2_tmki0"] +[ext_resource type="Script" path="res://src/props/flag/flag.gd" id="2_wv8rd"] [sub_resource type="ConcavePolygonShape3D" id="ConcavePolygonShape3D_8ynho"] data = PackedVector3Array(0, 0, -0.025, 0.0217, 4, -0.0125, 0, 4, -0.025, 0, 0, -0.025, 0.0217, 0, -0.0125, 0.0217, 4, -0.0125, 0.0217, 0, -0.0125, 0.0217, 4, 0.0125, 0.0217, 4, -0.0125, 0.0217, 0, -0.0125, 0.0217, 0, 0.0125, 0.0217, 4, 0.0125, 0.0217, 0, 0.0125, 0, 4, 0.025, 0.0217, 4, 0.0125, 0.0217, 0, 0.0125, 0, 0, 0.025, 0, 4, 0.025, 0, 0, 0.025, -0.0217, 4, 0.0125, 0, 4, 0.025, 0, 0, 0.025, -0.0217, 0, 0.0125, -0.0217, 4, 0.0125, 0.0217, 4, 0.0125, 0, 4, -0.025, 0.0217, 4, -0.0125, 0, 4, -0.025, -0.0217, 4, 0.0125, -0.0217, 4, -0.0125, -0.0217, 4, 0.0125, 0.0217, 4, 0.0125, 0, 4, 0.025, 0, 4, -0.025, 0.0217, 4, 0.0125, -0.0217, 4, 0.0125, -0.0217, 0, 0.0125, -0.0217, 4, -0.0125, -0.0217, 4, 0.0125, -0.0217, 0, 0.0125, -0.0217, 0, -0.0125, -0.0217, 4, -0.0125, -0.0217, 0, -0.0125, 0, 4, -0.025, -0.0217, 4, -0.0125, -0.0217, 0, -0.0125, 0, 0, -0.025, 0, 4, -0.025, -0.0217, 0, -0.0125, 0.0217, 0, -0.0125, 0, 0, -0.025, 0.0217, 0, -0.0125, 0, 0, 0.025, 0.0217, 0, 0.0125, 0, 0, 0.025, -0.0217, 0, -0.0125, -0.0217, 0, 0.0125, 0.0217, 0, -0.0125, -0.0217, 0, -0.0125, 0, 0, 0.025) [node name="Flag" instance=ExtResource("1_ona6u")] +script = ExtResource("2_wv8rd") +show_distance = true + +[node name="DistanceLabel" type="Label3D" parent="Pole" index="0"] +unique_name_in_owner = true +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 5, 0) +visibility_range_begin = 20.0 +visibility_range_begin_margin = 2.0 +visibility_range_fade_mode = 1 +pixel_size = 0.001 +billboard = 1 +no_depth_test = true +fixed_size = true +texture_filter = 5 +render_priority = 3 +outline_render_priority = 2 +outline_modulate = Color(1, 0, 0.133333, 1) +text = "Goal! +0000 m" +font = ExtResource("2_tmki0") +outline_size = 8 +line_spacing = -16.0 [node name="Skeleton3D" parent="Armature" index="0"] bones/0/rotation = Quaternion(-0.0471389, 2.3332e-10, 0.0444053, 0.997901)