diff --git a/entities/components/flag_carry_component.gd b/entities/components/flag_carry_component.gd
index d9f6e49..d33fcdc 100644
--- a/entities/components/flag_carry_component.gd
+++ b/entities/components/flag_carry_component.gd
@@ -12,51 +12,43 @@
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see .
+## This component allows its entity to interact with flags
class_name FlagCarryComponent extends Node3D
-## This component allows its entity to grab, carry and throw flags
-##
-## To work correctly the owner MUST set an attachment point for carried flags
-## and a sensor to detect when flags are within grab range
@export var max_throw_speed : float = 10.0
-@export var sensor : Area3D
-@export var carrier : Player
+@export var mesh : Node3D
var _carried_flag : Flag
-func _ready() -> void:
- sensor.body_entered.connect(_sensor_on_body_entered)
-
-func _physics_process(_delta : float) -> void:
+func _process(_delta : float) -> void:
if _is_carrying():
_carried_flag.global_position = global_position
- _carried_flag.global_rotation = global_rotation
-
-func _grab(flag : Flag) -> void:
- if not _is_carrying():
- flag.grab(carrier)
- _carried_flag = flag
- show()
-
-func _release(inherited_velocity : Vector3, throw_speed : float, dropper : Player) -> void:
- if _is_carrying():
- _carried_flag.drop(dropper)
- _carried_flag.rotation_degrees.x = 0.0
- _carried_flag.linear_velocity = inherited_velocity + (global_basis.z * throw_speed)
- # Throw the flag from some distance in front of the player to avoid regrabbing mid-air
- _carried_flag.global_position = carrier.global_position + (global_basis.z * 1.7)
- _carried_flag = null
- hide()
+ _carried_flag.global_rotation = Vector3(.0, global_rotation.y, .0)
func _is_carrying() -> bool:
return _carried_flag != null
-func _sensor_on_body_entered(collider : Flag) -> void:
- if collider is Flag:
- _grab(collider)
+func grab(flag : Flag) -> void:
+ if not _is_carrying():
+ flag.grabbed.emit(owner)
+ _carried_flag = flag
+ show()
func drop(dropper : Player) -> void:
_release(Vector3.ZERO, 0.0, dropper)
func throw(inherited_velocity : Vector3, dropper : Player) -> void:
_release(inherited_velocity, max_throw_speed, dropper)
+
+func _release(inherited_velocity : Vector3, throw_speed : float, dropper : Player) -> void:
+ if not _is_carrying():
+ return
+ # update carried flag global rotation based on component global rotation
+ _carried_flag.global_rotation = Vector3(.0, global_rotation.y, .0)
+ _carried_flag.linear_velocity = inherited_velocity + (global_basis.z * throw_speed)
+ # Throw the flag from some distance in front of the player to avoid regrabbing mid-air
+ _carried_flag.global_position = owner.global_position + (global_basis.z * 1.7)
+ _carried_flag.dropped.emit(dropper)
+ _carried_flag = null
+ hide()
+
diff --git a/entities/dummy_target/dummy_target.tscn b/entities/dummy_target/dummy_target.tscn
index 62806d3..54dc3f3 100644
--- a/entities/dummy_target/dummy_target.tscn
+++ b/entities/dummy_target/dummy_target.tscn
@@ -1,7 +1,7 @@
[gd_scene load_steps=5 format=3 uid="uid://dpnu1lvfncx6q"]
[ext_resource type="Script" path="res://entities/dummy_target/dummy_target.gd" id="1_iup5v"]
-[ext_resource type="Shape3D" uid="uid://cb8esdlnottdn" path="res://entities/player/collision_shape.tres" id="2_i5k5j"]
+[ext_resource type="Shape3D" uid="uid://cb8esdlnottdn" path="res://entities/player/resources/collider.tres" id="2_i5k5j"]
[ext_resource type="PackedScene" uid="uid://chuein4frnvwt" path="res://entities/dummy_target/assets/player_mesh.glb" id="4_fuync"]
[sub_resource type="PhysicsMaterial" id="PhysicsMaterial_b0142"]
diff --git a/entities/flag/assets/flag.glb b/entities/flag/assets/flag.glb
index 391e0ac..9fe08cc 100644
Binary files a/entities/flag/assets/flag.glb and b/entities/flag/assets/flag.glb differ
diff --git a/entities/flag/flag.gd b/entities/flag/flag.gd
index 79c3a67..e1b0013 100644
--- a/entities/flag/flag.gd
+++ b/entities/flag/flag.gd
@@ -12,34 +12,39 @@
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see .
-class_name Flag extends Node3D
-
-enum FlagState { FLAG_STATE_ON_STAND, FLAG_STATE_DROPPED, FLAG_STATE_TAKEN }
-
-@export var flag_state : FlagState = FlagState.FLAG_STATE_ON_STAND
+class_name Flag extends RigidBody3D
signal grabbed(grabber : Player)
signal regrabbed(grabber : Player)
signal dropped(dropper : Player)
+enum FlagState { ON_STAND, DROPPED, TAKEN }
+
+@export var state : FlagState = FlagState.ON_STAND
+
+@onready var area : Area3D = $GripArea3D
+@onready var mesh : Node3D = $Mesh
+
var last_carrier : Player = null
-@onready var _mesh : Node = $Smoothing/Mesh
-func can_be_grabbed() -> bool:
- return flag_state != FlagState.FLAG_STATE_TAKEN
+func _ready() -> void:
+ area.body_entered.connect(_on_body_entered)
-func grab(grabber : Player) -> void:
- if flag_state != FlagState.FLAG_STATE_TAKEN:
- _mesh.hide()
- flag_state = FlagState.FLAG_STATE_TAKEN
+func _on_grabbed(grabber : Player) -> void:
+ if state != FlagState.TAKEN:
+ hide()
+ state = FlagState.TAKEN
if (last_carrier == null) or (grabber != last_carrier):
- grabbed.emit(grabber)
last_carrier = grabber
else:
regrabbed.emit(grabber)
-func drop(dropper : Player) -> void:
- if flag_state == FlagState.FLAG_STATE_TAKEN:
- _mesh.show()
- flag_state = FlagState.FLAG_STATE_DROPPED
- dropped.emit(dropper)
+func _on_dropped(_dropper : Player) -> void:
+ if state == FlagState.TAKEN:
+ show()
+ state = FlagState.DROPPED
+
+func _on_body_entered(body: Node) -> void:
+ if body is Player:
+ assert(body.flag_carry_component)
+ body.flag_carry_component.grab(self)
diff --git a/entities/flag/flag.tscn b/entities/flag/flag.tscn
index c1a5337..1b1a89a 100644
--- a/entities/flag/flag.tscn
+++ b/entities/flag/flag.tscn
@@ -1,17 +1,15 @@
[gd_scene load_steps=8 format=3 uid="uid://c88l3h0ph00c7"]
[ext_resource type="Script" path="res://entities/flag/flag.gd" id="1_y7d3d"]
-[ext_resource type="Script" path="res://addons/smoothing/smoothing.gd" id="2_es4ce"]
[ext_resource type="PackedScene" uid="uid://d3l7fvbdg6m5g" path="res://entities/flag/assets/flag.glb" id="2_i78em"]
-[ext_resource type="PackedScene" uid="uid://bcgkc5fhhyauv" path="res://entities/flag/waypoint.tscn" id="3_tu6jg"]
+[ext_resource type="Shape3D" uid="uid://dfko4x6uq27q" path="res://entities/flag/resources/collider.tres" id="2_kx0v0"]
+[ext_resource type="Shape3D" uid="uid://b5a6oybteqj6n" path="res://entities/flag/resources/grip_area.tres" id="3_uhsc8"]
+[ext_resource type="PackedScene" uid="uid://2350a3ce4xs8" path="res://interfaces/waypoint/waypoint3d.tscn" id="4_y8nj0"]
[sub_resource type="PhysicsMaterial" id="PhysicsMaterial_4ymrw"]
friction = 0.5
bounce = 0.5
-[sub_resource type="BoxShape3D" id="BoxShape3D_fkf1k"]
-size = Vector3(0.5, 2.33994, 0.5)
-
[sub_resource type="SceneReplicationConfig" id="SceneReplicationConfig_lpijf"]
properties/0/path = NodePath(".:position")
properties/0/spawn = true
@@ -19,10 +17,10 @@ properties/0/replication_mode = 1
properties/1/path = NodePath(".:linear_velocity")
properties/1/spawn = true
properties/1/replication_mode = 1
-properties/2/path = NodePath(".:flag_state")
+properties/2/path = NodePath("Smoothing/Mesh:visible")
properties/2/spawn = true
properties/2/replication_mode = 2
-properties/3/path = NodePath("Smoothing/Mesh:visible")
+properties/3/path = NodePath("Flag:state")
properties/3/spawn = true
properties/3/replication_mode = 2
@@ -40,20 +38,23 @@ continuous_cd = true
script = ExtResource("1_y7d3d")
[node name="CollisionShape3D" type="CollisionShape3D" parent="."]
-transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.175, 0)
-shape = SubResource("BoxShape3D_fkf1k")
+transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0.00601196)
+shape = ExtResource("2_kx0v0")
+
+[node name="GripArea3D" type="Area3D" parent="."]
+
+[node name="CollisionShape3D" type="CollisionShape3D" parent="GripArea3D"]
+transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0)
+shape = ExtResource("3_uhsc8")
+
+[node name="Mesh" parent="." instance=ExtResource("2_i78em")]
+
+[node name="Waypoint" parent="." instance=ExtResource("4_y8nj0")]
+transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 2.25, 0)
+foreground_color = Color(0, 0.75, 0.75, 1)
[node name="MultiplayerSynchronizer" type="MultiplayerSynchronizer" parent="."]
replication_config = SubResource("SceneReplicationConfig_lpijf")
-[node name="Smoothing" type="Node3D" parent="."]
-script = ExtResource("2_es4ce")
-
-[node name="WaypointAttachment" type="Marker3D" parent="Smoothing"]
-
-[node name="Waypoint" parent="Smoothing/WaypointAttachment" node_paths=PackedStringArray("attach_point", "flag") instance=ExtResource("3_tu6jg")]
-attach_point = NodePath("..")
-flag = NodePath("../../..")
-
-[node name="Mesh" parent="Smoothing" instance=ExtResource("2_i78em")]
-transform = Transform3D(0.5, 0, 0, 0, 0.5, 0, 0, 0, 0.5, 0, 0.0744106, 0)
+[connection signal="dropped" from="." to="." method="_on_dropped"]
+[connection signal="grabbed" from="." to="." method="_on_grabbed"]
diff --git a/entities/flag/resources/collider.tres b/entities/flag/resources/collider.tres
new file mode 100644
index 0000000..d2f56f4
--- /dev/null
+++ b/entities/flag/resources/collider.tres
@@ -0,0 +1,4 @@
+[gd_resource type="BoxShape3D" format=3 uid="uid://dfko4x6uq27q"]
+
+[resource]
+size = Vector3(0.5, 2, 0.164246)
diff --git a/entities/flag/resources/grip_area.tres b/entities/flag/resources/grip_area.tres
new file mode 100644
index 0000000..cb56f58
--- /dev/null
+++ b/entities/flag/resources/grip_area.tres
@@ -0,0 +1,4 @@
+[gd_resource type="BoxShape3D" format=3 uid="uid://b5a6oybteqj6n"]
+
+[resource]
+size = Vector3(0.5, 2, 0.5)
diff --git a/entities/flag/waypoint.gd b/entities/flag/waypoint.gd
deleted file mode 100644
index 12d6741..0000000
--- a/entities/flag/waypoint.gd
+++ /dev/null
@@ -1,52 +0,0 @@
-# This file is part of open-fpsz.
-#
-# This program is free software: you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation, either version 3 of the License, or
-# (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program. If not, see .
-extends Control
-
-@export var attach_point : Node3D
-@export var flag : Flag
-
-@onready var _iff_container : Control = $IFFContainer
-
-func _ready() -> void:
- attach_point.transform = attach_point.transform.translated(
- Vector3(0, flag.get_node("CollisionShape3D").shape.size.y, 0))
-
-func _process(_delta : float) -> void:
- # disable waypoint repositioning when running headless
- if DisplayServer.get_name() == "headless":
- set_process(false)
- return
-
- # repositon iff on viewport
- var camera : Camera3D = get_viewport().get_camera_3d()
- var viewport_rect : Rect2 = get_viewport_rect()
- # if the player is NOT infront of the camera or camera does NOT have LOS to player
- if camera.is_position_behind(attach_point.global_position):
- _iff_container.hide() # hide the IFF and exit function
- return
- else:
- _iff_container.show() # display the IFF
- # get the screen location of the players head
- var new_iff_position : Vector2 = camera.unproject_position(attach_point.global_position)
- # check if the unprojected point lies inside the viewport
- if !Rect2(Vector2(0, 0), viewport_rect.size).has_point(new_iff_position):
- _iff_container.hide() # hide the IFF and exit function
- return
- # move the IFF up so the bottom of it is at the players head
- new_iff_position.y -= _iff_container.size.y
- # move the IFF left so it's centered horizontally above players head
- new_iff_position.x -= _iff_container.size.x / 2
- # set the position of the IFF
- position = new_iff_position
diff --git a/entities/flag/waypoint.tscn b/entities/flag/waypoint.tscn
deleted file mode 100644
index a3f5cc5..0000000
--- a/entities/flag/waypoint.tscn
+++ /dev/null
@@ -1,27 +0,0 @@
-[gd_scene load_steps=2 format=3 uid="uid://bcgkc5fhhyauv"]
-
-[ext_resource type="Script" path="res://entities/flag/waypoint.gd" id="1_gmnl6"]
-
-[node name="IFF" type="Control"]
-layout_mode = 3
-anchors_preset = 0
-script = ExtResource("1_gmnl6")
-
-[node name="IFFContainer" type="MarginContainer" parent="."]
-layout_mode = 0
-offset_right = 11.0
-offset_bottom = 20.0
-mouse_filter = 2
-
-[node name="Chevron" type="Label" parent="IFFContainer"]
-layout_direction = 2
-layout_mode = 2
-size_flags_vertical = 1
-theme_override_colors/font_color = Color(0, 1, 1, 0.784314)
-theme_override_colors/font_outline_color = Color(0, 0, 0, 1)
-theme_override_constants/outline_size = 3
-theme_override_constants/line_spacing = -20
-theme_override_font_sizes/font_size = 14
-text = "▼"
-horizontal_alignment = 1
-vertical_alignment = 2
diff --git a/entities/player/player.gd b/entities/player/player.gd
index c4ddee0..96d807b 100644
--- a/entities/player/player.gd
+++ b/entities/player/player.gd
@@ -18,6 +18,7 @@ enum PlayerState { PLAYER_ALIVE, PLAYER_DEAD }
@export var iff : Control
@export var health_component : HealthComponent
+@export var flag_carry_component : FlagCarryComponent
@export var walkable_surface_sensor : ShapeCast3D
## The inventory component can store up to [member Inventory.slots] objects. It
@@ -49,7 +50,6 @@ enum PlayerState { PLAYER_ALIVE, PLAYER_DEAD }
@onready var hud : CanvasLayer = $HUD
@onready var animation_player : AnimationPlayer = $AnimationPlayer
@onready var collision_shape : CollisionShape3D = $CollisionShape3D
-@onready var flag_carry_component : FlagCarryComponent = %Pivot/FlagCarryComponent
@onready var jetpack_particles : Array = $Smoothing/ThirdPerson/Mesh/JetpackFX.get_children()
@onready var match_participant_component : MatchParticipantComponent = $MatchParticipantComponent
@@ -65,7 +65,6 @@ static var pawn_player : Player
func _ready() -> void:
match_participant_component.player_id_changed.connect(_setup_pawn)
match_participant_component.player_id_changed.connect(input.update_multiplayer_authority)
- match_participant_component.nickname_changed.connect(iff.set_nickname)
health_component.health_changed.connect(hud._on_health_changed)
health_component.health_changed.connect(iff._on_health_changed)
health_component.health_changed.emit(health_component.health)
diff --git a/entities/player/player.tscn b/entities/player/player.tscn
index dfaaac4..5ecea45 100644
--- a/entities/player/player.tscn
+++ b/entities/player/player.tscn
@@ -1,8 +1,8 @@
[gd_scene load_steps=45 format=3 uid="uid://cbhx1xme0sb7k"]
[ext_resource type="Script" path="res://entities/player/player.gd" id="1_mk68k"]
-[ext_resource type="Shape3D" uid="uid://cb8esdlnottdn" path="res://entities/player/collision_shape.tres" id="2_vjqny"]
[ext_resource type="PackedScene" uid="uid://bcv81ku26xo" path="res://interfaces/hud/hud.tscn" id="3_ccety"]
+[ext_resource type="Shape3D" uid="uid://cb8esdlnottdn" path="res://entities/player/resources/collider.tres" id="4_8kvcy"]
[ext_resource type="Script" path="res://entities/components/match_participant_component.gd" id="6_lrose"]
[ext_resource type="Script" path="res://entities/player/player_input.gd" id="6_ymcrr"]
[ext_resource type="PackedScene" uid="uid://dsysi2rd3bu76" path="res://interfaces/hud/iffs/iff.tscn" id="7_8hc80"]
@@ -206,8 +206,9 @@ particles_anim_loop = false
[sub_resource type="QuadMesh" id="QuadMesh_uc7ts"]
material = SubResource("StandardMaterial3D_2jwv2")
-[node name="Player" type="RigidBody3D" node_paths=PackedStringArray("iff", "health_component", "walkable_surface_sensor", "inventory", "tp_mesh") groups=["Player"]]
+[node name="Player" type="RigidBody3D" node_paths=PackedStringArray("iff", "health_component", "flag_carry_component", "walkable_surface_sensor", "inventory", "tp_mesh") groups=["Player"]]
collision_mask = 2147483649
+collision_priority = 9.0
axis_lock_angular_x = true
axis_lock_angular_y = true
axis_lock_angular_z = true
@@ -216,27 +217,20 @@ physics_material_override = SubResource("PhysicsMaterial_clur0")
can_sleep = false
continuous_cd = true
script = ExtResource("1_mk68k")
-iff = NodePath("Smoothing/ThirdPerson/IFF")
+iff = NodePath("Smoothing/ThirdPerson/IFFAttachment/IFF")
health_component = NodePath("HealthComponent")
+flag_carry_component = NodePath("Pivot/FlagCarryComponent")
walkable_surface_sensor = NodePath("WalkableSurfaceSensor")
inventory = NodePath("Pivot/Inventory")
tp_mesh = NodePath("Smoothing/ThirdPerson/Mesh")
jump_height = 1.5
-[node name="Sensor" type="Area3D" parent="."]
-collision_layer = 0
-collision_mask = 8
-monitorable = false
-
-[node name="CollisionShape3D" type="CollisionShape3D" parent="Sensor"]
-shape = ExtResource("2_vjqny")
-
[node name="HealthComponent" type="Area3D" parent="." node_paths=PackedStringArray("match_participant_component")]
script = ExtResource("14_ctgxn")
match_participant_component = NodePath("../MatchParticipantComponent")
[node name="CollisionShape3D" type="CollisionShape3D" parent="HealthComponent"]
-shape = ExtResource("2_vjqny")
+shape = ExtResource("4_8kvcy")
[node name="WalkableSurfaceSensor" type="ShapeCast3D" parent="."]
transform = Transform3D(1.05, 0, 0, 0, 1.05, 0, 0, 0, 1.05, 0, -0.85, 0)
@@ -245,7 +239,7 @@ target_position = Vector3(0, 0, 0)
collision_mask = 2147483648
[node name="CollisionShape3D" type="CollisionShape3D" parent="."]
-shape = ExtResource("2_vjqny")
+shape = ExtResource("4_8kvcy")
[node name="HUD" parent="." instance=ExtResource("3_ccety")]
@@ -295,19 +289,17 @@ visible = false
[node name="GrenadeLauncher" parent="Pivot/Inventory" instance=ExtResource("16_4xs2j")]
visible = false
-[node name="FlagCarryComponent" type="Node3D" parent="Pivot" node_paths=PackedStringArray("sensor", "carrier")]
-transform = Transform3D(-1, 0, -8.74228e-08, 0, 1, 0, 8.74228e-08, 0, -1, 0, 0, 0)
-visible = false
-script = ExtResource("8_pdfbn")
-sensor = NodePath("../../Sensor")
-carrier = NodePath("../..")
-
-[node name="FlagMesh" parent="Pivot/FlagCarryComponent" instance=ExtResource("18_7nkei")]
-transform = Transform3D(0.5, 0, 0, 0, 0.5, 0, 0, 0, 0.5, 1.559e-08, -0.462981, -0.178329)
-
[node name="SpineIKTarget" type="Marker3D" parent="Pivot"]
transform = Transform3D(-1, 0, -8.74228e-08, 0, 1, 0, 8.74228e-08, 0, -1, 0, 0, 0)
+[node name="FlagCarryComponent" type="Node3D" parent="Pivot" node_paths=PackedStringArray("mesh")]
+transform = Transform3D(-1, 0, -8.74228e-08, 0, 1, 0, 8.74228e-08, 0, -1, 0, -0.25, 0.377972)
+visible = false
+script = ExtResource("8_pdfbn")
+mesh = NodePath("FlagMesh")
+
+[node name="FlagMesh" parent="Pivot/FlagCarryComponent" instance=ExtResource("18_7nkei")]
+
[node name="Smoothing" type="Node3D" parent="."]
script = ExtResource("11_k330l")
target = NodePath("..")
@@ -329,7 +321,6 @@ bones/6/rotation = Quaternion(0.160951, 0.00623474, 0.0096637, 0.986895)
bones/8/rotation = Quaternion(0.675761, -0.399581, 0.409695, 0.464577)
bones/10/rotation = Quaternion(0.212344, -0.0870591, -0.287653, 0.929831)
bones/12/rotation = Quaternion(0.0811501, 0.206806, -0.754068, 0.618084)
-bones/14/position = Vector3(-0.074525, 0.220475, 0.075475)
bones/14/rotation = Quaternion(0.00943715, 0.0971687, -0.145046, 0.984597)
bones/20/rotation = Quaternion(-0.123455, 0.0248346, 0.23344, 0.964183)
bones/24/rotation = Quaternion(0.0450683, -0.000817796, 0.0508488, 0.997689)
@@ -347,9 +338,8 @@ bones/56/rotation = Quaternion(-0.0254885, 0.0439755, -0.00910637, 0.998666)
bones/58/rotation = Quaternion(-0.0119802, 0.289956, -0.0527053, 0.955513)
bones/62/rotation = Quaternion(0.689943, 0.375565, -0.410267, 0.463261)
bones/64/rotation = Quaternion(0.337746, -0.290519, 0.159479, 0.880961)
-bones/66/position = Vector3(0.055475, 0.231475, 0.000474975)
bones/66/rotation = Quaternion(0.540371, -0.580679, 0.406779, 0.453147)
-bones/68/position = Vector3(-0.014525, 0.270475, -0.054525)
+bones/68/position = Vector3(-1.77636e-17, 0.240718, 0)
bones/68/rotation = Quaternion(0.0150529, -0.289001, 0.0720108, 0.954498)
bones/70/rotation = Quaternion(0.155965, 0.0109114, -0.00107202, 0.987702)
bones/72/rotation = Quaternion(0.563923, 4.19095e-08, -0.0577906, 0.823803)
@@ -376,7 +366,7 @@ bones/124/rotation = Quaternion(0.417677, -0.0431149, 0.00625689, 0.90755)
bones/126/rotation = Quaternion(0.397818, -0.0427722, -0.00601182, 0.916447)
[node name="HandAttachment" parent="Smoothing/ThirdPerson/Mesh/Node/Skeleton3D" index="0"]
-transform = Transform3D(-0.152214, 0.0548832, 0.986823, 0.933991, 0.334546, 0.125459, -0.323252, 0.94078, -0.102183, -0.191759, 1.06335, 0.0698007)
+transform = Transform3D(-0.152214, 0.0548832, 0.986823, 0.933991, 0.334546, 0.125459, -0.323252, 0.94078, -0.102183, -0.261612, 1.14328, 0.0896011)
[node name="grip" parent="Smoothing/ThirdPerson/Mesh/Node/Skeleton3D/HandAttachment/SpaceGun/Mesh/Armature/Skeleton3D" index="0"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 2.84217e-14, 1.19209e-07, 2.38419e-07)
@@ -400,7 +390,13 @@ transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.692504, 1.30946)
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.692504, 1.30946)
[node name="Barrels" parent="Smoothing/ThirdPerson/Mesh/Node/Skeleton3D/HandAttachment/ChainGun" index="3"]
-transform = Transform3D(-1, 0, 8.9407e-08, 8.47504e-08, 0, 1, 0, 1, -3.72529e-09, 0, -2.38419e-07, -0.55315)
+transform = Transform3D(-1, -1.49012e-08, 8.801e-08, 8.19564e-08, -3.72529e-09, 1, 0, 1, -7.45058e-09, 5.96046e-08, 0, -0.55315)
+
+[node name="Skeleton3D" parent="Smoothing/ThirdPerson/Mesh/Node/Skeleton3D/HandAttachment/GrenadeLauncher/Armature" index="0"]
+bones/0/rotation = Quaternion(0, 0.707107, 0.707107, 0)
+bones/1/rotation = Quaternion(0, 0.707107, 0.707107, 0)
+bones/2/rotation = Quaternion(0, 0.707107, 0.707107, 0)
+bones/3/rotation = Quaternion(0, 0.707107, 0.707107, 0)
[node name="barrel" parent="Smoothing/ThirdPerson/Mesh/Node/Skeleton3D/HandAttachment/GrenadeLauncher/Armature/Skeleton3D" index="0"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.19209e-07, 0)
@@ -443,11 +439,13 @@ draw_pass_1 = SubResource("QuadMesh_uc7ts")
[node name="IFFAttachment" type="Marker3D" parent="Smoothing/ThirdPerson"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.27457, 0)
+visible = false
-[node name="IFF" parent="Smoothing/ThirdPerson" node_paths=PackedStringArray("player", "match_participant_component", "attach_point") instance=ExtResource("7_8hc80")]
-player = NodePath("../../..")
-match_participant_component = NodePath("../../../MatchParticipantComponent")
-attach_point = NodePath("../IFFAttachment")
+[node name="IFF" parent="Smoothing/ThirdPerson/IFFAttachment" node_paths=PackedStringArray("player", "match_participant_component", "attach_point") instance=ExtResource("7_8hc80")]
+visible = false
+player = NodePath("../../../..")
+match_participant_component = NodePath("../../../../MatchParticipantComponent")
+attach_point = NodePath("..")
[connection signal="energy_changed" from="." to="HUD" method="_on_player_energy_changed"]
diff --git a/entities/player/collision_shape.tres b/entities/player/resources/collider.tres
similarity index 100%
rename from entities/player/collision_shape.tres
rename to entities/player/resources/collider.tres
diff --git a/interfaces/waypoint/assets/waypoint.svg b/interfaces/waypoint/assets/waypoint.svg
new file mode 100644
index 0000000..6a5a1b0
--- /dev/null
+++ b/interfaces/waypoint/assets/waypoint.svg
@@ -0,0 +1 @@
+
diff --git a/interfaces/waypoint/assets/waypoint.svg.import b/interfaces/waypoint/assets/waypoint.svg.import
new file mode 100644
index 0000000..600e8c8
--- /dev/null
+++ b/interfaces/waypoint/assets/waypoint.svg.import
@@ -0,0 +1,38 @@
+[remap]
+
+importer="texture"
+type="CompressedTexture2D"
+uid="uid://cpb6vpa0c74rl"
+path.s3tc="res://.godot/imported/waypoint.svg-e7e029f470e2f863636e9426f3893ced.s3tc.ctex"
+metadata={
+"imported_formats": ["s3tc_bptc"],
+"vram_texture": true
+}
+
+[deps]
+
+source_file="res://interfaces/waypoint/assets/waypoint.svg"
+dest_files=["res://.godot/imported/waypoint.svg-e7e029f470e2f863636e9426f3893ced.s3tc.ctex"]
+
+[params]
+
+compress/mode=2
+compress/high_quality=false
+compress/lossy_quality=0.7
+compress/hdr_compression=1
+compress/normal_map=0
+compress/channel_pack=0
+mipmaps/generate=true
+mipmaps/limit=-1
+roughness/mode=0
+roughness/src_normal=""
+process/fix_alpha_border=true
+process/premult_alpha=false
+process/normal_map_invert_y=false
+process/hdr_as_srgb=false
+process/hdr_clamp_exposure=false
+process/size_limit=0
+detect_3d/compress_to=0
+svg/scale=1.0
+editor/scale_with_editor_scale=false
+editor/convert_colors_with_editor_theme=false
diff --git a/interfaces/waypoint/waypoint.gd b/interfaces/waypoint/waypoint.gd
new file mode 100644
index 0000000..a3113dc
--- /dev/null
+++ b/interfaces/waypoint/waypoint.gd
@@ -0,0 +1,129 @@
+# This file is part of open-fpsz.
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see .
+extends Control
+
+# Some margin to keep the marker away from the screen's corners.
+const MARGIN : float = 8.
+
+# If `true`, the waypoint sticks to the viewport's edges when moving off-screen.
+@export var sticky : bool = true
+
+# If `true`, the waypoint fades as the camera get closer.
+@export var fade : bool = true
+
+# The waypoint's text.
+@export var text : String = "Waypoint":
+ set(value):
+ text = value
+ # The label's text can only be set once the node is ready.
+ if is_inside_tree():
+ label.text = value
+
+@onready var camera : Camera3D = get_viewport().get_camera_3d()
+@onready var label : Label = $Label
+@onready var parent : Node = get_parent()
+
+func _ready() -> void:
+ self.text = text
+ if not parent is Node3D:
+ push_error("The waypoint's parent node must inherit from Node3D.")
+ if DisplayServer.get_name() == "headless":
+ parent.queue_free()
+
+func _process(_delta : float) -> void:
+ if not camera.current:
+ # If the camera we have isn't the current one, get the current camera.
+ camera = get_viewport().get_camera_3d()
+
+ var parent_position : Vector3 = parent.global_transform.origin
+ var camera_transform : Transform3D = camera.global_transform
+ var camera_position : Vector3 = camera_transform.origin
+
+ # We would use "camera.is_position_behind(parent_position)", except
+ # that it also accounts for the near clip plane, which we don't want.
+ var is_behind : bool = camera_transform.basis.z.dot(parent_position - camera_position) > 0
+
+ # Fade the waypoint when the camera gets close.
+ if fade:
+ var distance : float = camera_position.distance_to(parent_position)
+ modulate.a = remap(distance, 0., 256., 0., 1.)
+
+ var unprojected_position : Vector2 = camera.unproject_position(parent_position)
+ var viewport_size : Vector2 = get_viewport_rect().size
+
+ if not sticky:
+ # For non-sticky waypoints, we don't need to clamp and calculate
+ # the position if the waypoint goes off screen.
+ position = unprojected_position
+ visible = not is_behind
+ return
+
+ # We need to handle the axes differently.
+ # For the screen's X axis, the projected position is useful to us,
+ # but we need to force it to the side if it's also behind.
+ if is_behind:
+ if unprojected_position.x < viewport_size.x / 2.:
+ unprojected_position.x = viewport_size.x - MARGIN
+ else:
+ unprojected_position.x = MARGIN
+
+ # For the screen's Y axis, the projected position is NOT useful to us
+ # because we don't want to indicate to the user that they need to look
+ # up or down to see something behind them. Instead, here we approximate
+ # the correct position using difference of the X axis Euler angles
+ # (up/down rotation) and the ratio of that with the camera's FOV.
+ # This will be slightly off from the theoretical "ideal" position.
+ if is_behind or unprojected_position.x < MARGIN or \
+ unprojected_position.x > viewport_size.x - MARGIN:
+ var look : Transform3D = camera_transform.looking_at(parent_position, Vector3.UP)
+ var diff : float = angle_diff(
+ look.basis.get_euler().x, camera_transform.basis.get_euler().x)
+ unprojected_position.y = viewport_size.y * (0.5 + (diff / deg_to_rad(camera.fov)))
+
+ position = Vector2(
+ clamp(unprojected_position.x, MARGIN, viewport_size.x - MARGIN),
+ clamp(unprojected_position.y, MARGIN, viewport_size.y - MARGIN)
+ )
+
+ label.visible = true
+ rotation = 0
+ # Used to display a diagonal arrow when the waypoint is displayed in
+ # one of the screen corners.
+ var overflow : float = .0
+
+ if position.x <= MARGIN:
+ # Left overflow.
+ overflow = -TAU / 8.0
+ label.visible = false
+ rotation = TAU / 4.0
+ elif position.x >= viewport_size.x - MARGIN:
+ # Right overflow.
+ overflow = TAU / 8.0
+ label.visible = false
+ rotation = TAU * 3.0 / 4.0
+
+ if position.y <= MARGIN:
+ # Top overflow.
+ label.visible = false
+ rotation = TAU / 2.0 + overflow
+ elif position.y >= viewport_size.y - MARGIN:
+ # Bottom overflow.
+ label.visible = false
+ rotation = -overflow
+
+
+static func angle_diff(from : float, to : float) -> float:
+ var diff : float = fmod(to - from, TAU)
+ return fmod(2.0 * diff, TAU) - diff
diff --git a/interfaces/waypoint/waypoint.tscn b/interfaces/waypoint/waypoint.tscn
new file mode 100644
index 0000000..6a0f401
--- /dev/null
+++ b/interfaces/waypoint/waypoint.tscn
@@ -0,0 +1,30 @@
+[gd_scene load_steps=3 format=3 uid="uid://bcgkc5fhhyauv"]
+
+[ext_resource type="Script" path="res://interfaces/waypoint/waypoint.gd" id="1_gmnl6"]
+[ext_resource type="Texture2D" uid="uid://cpb6vpa0c74rl" path="res://interfaces/waypoint/assets/waypoint.svg" id="2_xby6k"]
+
+[node name="Waypoint" type="Control"]
+layout_mode = 3
+anchors_preset = 0
+size_flags_horizontal = 3
+script = ExtResource("1_gmnl6")
+fade = false
+
+[node name="Marker" type="TextureRect" parent="."]
+visible = false
+layout_mode = 0
+offset_left = -8.0
+offset_top = -16.0
+offset_right = 8.0
+texture = ExtResource("2_xby6k")
+expand_mode = 1
+
+[node name="Label" type="Label" parent="."]
+layout_mode = 0
+offset_left = -128.0
+offset_top = -42.0
+offset_right = 128.0
+offset_bottom = -19.0
+theme_override_font_sizes/font_size = 14
+horizontal_alignment = 1
+vertical_alignment = 2
diff --git a/interfaces/waypoint/waypoint3d.gd b/interfaces/waypoint/waypoint3d.gd
new file mode 100644
index 0000000..d4311a9
--- /dev/null
+++ b/interfaces/waypoint/waypoint3d.gd
@@ -0,0 +1,45 @@
+# This file is part of open-fpsz.
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see .
+@tool
+class_name Waypoint3D extends Node3D
+
+# If `true`, the waypoint sticks to the viewport's edges when moving off-screen.
+@export var sticky : bool = true
+
+# If `true`, the waypoint fades as the camera get closer.
+@export var fade : bool = true
+
+# The waypoint's text.
+@export var text : String:
+ set(value):
+ text = value
+ # The label's text can only be set once the node is ready.
+ if is_inside_tree():
+ label.text = value
+
+## The foreground color to modulate the waypoint color
+@export var foreground_color : Color = Color.WHITE
+
+@onready var label : Label3D = $Label3D
+@onready var sprite : Sprite3D = $Sprite3D
+
+# Called when the node enters the scene tree for the first time.
+func _ready() -> void:
+ pass
+
+func _process(_delta : float) -> void:
+ sprite.modulate = foreground_color
+ label.modulate = foreground_color
+ label.outline_modulate.a = foreground_color.a
diff --git a/interfaces/waypoint/waypoint3d.tscn b/interfaces/waypoint/waypoint3d.tscn
new file mode 100644
index 0000000..ed8c190
--- /dev/null
+++ b/interfaces/waypoint/waypoint3d.tscn
@@ -0,0 +1,23 @@
+[gd_scene load_steps=3 format=3 uid="uid://2350a3ce4xs8"]
+
+[ext_resource type="Texture2D" uid="uid://cpb6vpa0c74rl" path="res://interfaces/waypoint/assets/waypoint.svg" id="1_502g6"]
+[ext_resource type="Script" path="res://interfaces/waypoint/waypoint3d.gd" id="1_kq7bj"]
+
+[node name="Waypoint" type="Node3D"]
+script = ExtResource("1_kq7bj")
+
+[node name="Label3D" type="Label3D" parent="."]
+transform = Transform3D(0.5, 0, 0, 0, 0.5, 0, 0, 0, 0.5, 0, 0, 0)
+offset = Vector2(0, 48)
+billboard = 2
+no_depth_test = true
+fixed_size = true
+line_spacing = 32.025
+
+[node name="Sprite3D" type="Sprite3D" parent="."]
+transform = Transform3D(0.05, 0, 0, 0, 0.05, 0, 0, 0, 0.05, 0, 0, 0)
+offset = Vector2(0, 64)
+billboard = 2
+no_depth_test = true
+fixed_size = true
+texture = ExtResource("1_502g6")
diff --git a/project.godot b/project.godot
index d5fa618..9f5432c 100644
--- a/project.godot
+++ b/project.godot
@@ -42,6 +42,7 @@ gdscript/warnings/property_used_as_function=2
gdscript/warnings/constant_used_as_function=2
gdscript/warnings/function_used_as_property=2
gdscript/warnings/untyped_declaration=1
+gdscript/warnings/static_called_on_instance=0
[editor]
diff --git a/systems/global.gd b/systems/global.gd
index 1b374a0..740b524 100644
--- a/systems/global.gd
+++ b/systems/global.gd
@@ -27,7 +27,7 @@ var type : Node:
# keep reference to new type
type = new_type
if type != null:
- add_child(type)
+ get_tree().get_root().add_child(type)
type_changed.emit(type)
func _unhandled_input(event : InputEvent) -> void:
diff --git a/tests/test_flag.gd b/tests/test_flag.gd
index 78a87e7..b0a8055 100644
--- a/tests/test_flag.gd
+++ b/tests/test_flag.gd
@@ -29,46 +29,46 @@ func _is_mesh_visible() -> bool:
return mesh.is_visible()
func test_that_flag_is_on_stand_by_default() -> void:
- assert_eq(_subject.flag_state, Flag.FlagState.FLAG_STATE_ON_STAND)
+ assert_eq(_subject.flag_state, Flag.FlagState.ON_STAND)
func test_that_mesh_is_visible_by_default() -> void:
assert_true(_is_mesh_visible())
func test_that_flag_on_stand_can_be_grabbed() -> void:
- _subject.flag_state = Flag.FlagState.FLAG_STATE_ON_STAND
- assert_true(_subject.can_be_grabbed())
+ _subject.flag_state = Flag.FlagState.ON_STAND
+ assert_true(_subject.state != _subject.FlagState.TAKEN)
func test_that_dropped_flag_can_be_grabbed() -> void:
- _subject.flag_state = Flag.FlagState.FLAG_STATE_DROPPED
- assert_true(_subject.can_be_grabbed())
+ _subject.flag_state = Flag.FlagState.DROPPED
+ assert_true(_subject.state != _subject.FlagState.TAKEN)
func test_that_taken_flag_cannot_be_grabbed() -> void:
- _subject.flag_state = Flag.FlagState.FLAG_STATE_TAKEN
- assert_false(_subject.can_be_grabbed())
+ _subject.flag_state = Flag.FlagState.TAKEN
+ assert_false(_subject.state != _subject.FlagState.TAKEN)
func test_that_on_stand_flag_grab_emits_grab_signal_and_changes_state() -> void:
- _subject.flag_state = Flag.FlagState.FLAG_STATE_ON_STAND
+ _subject.flag_state = Flag.FlagState.ON_STAND
var player : Player = PLAYER.instantiate()
_subject.grab(player)
assert_signal_emitted_with_parameters(_subject, 'grabbed', [player])
- assert_eq(_subject.flag_state, Flag.FlagState.FLAG_STATE_TAKEN)
+ assert_eq(_subject.flag_state, Flag.FlagState.TAKEN)
assert_eq(_subject.last_carrier, player)
player.free()
func test_that_dropped_flag_grab_emits_grab_signal_and_changes_state() -> void:
- _subject.flag_state = Flag.FlagState.FLAG_STATE_DROPPED
+ _subject.flag_state = Flag.FlagState.DROPPED
var player : Player = PLAYER.instantiate()
_subject.grab(player)
assert_signal_emitted_with_parameters(_subject, 'grabbed', [player])
- assert_eq(_subject.flag_state, Flag.FlagState.FLAG_STATE_TAKEN)
+ assert_eq(_subject.flag_state, Flag.FlagState.TAKEN)
assert_eq(_subject.last_carrier, player)
player.free()
func test_that_taken_flag_grab_does_not_emit_grab_signal_and_keeps_state() -> void:
- _subject.flag_state = Flag.FlagState.FLAG_STATE_TAKEN
+ _subject.flag_state = Flag.FlagState.TAKEN
_subject.grab(null) # doesn't matter that it's null in this case
assert_signal_not_emitted(_subject, 'grabbed')
- assert_eq(_subject.flag_state, Flag.FlagState.FLAG_STATE_TAKEN)
+ assert_eq(_subject.flag_state, Flag.FlagState.TAKEN)
assert_null(_subject.last_carrier)
func test_that_flag_grab_hides_mesh() -> void:
@@ -82,14 +82,14 @@ func test_that_taken_flag_drop_emits_signal_and_changes_state() -> void:
_subject.grab(player)
_subject.drop(player)
assert_signal_emitted_with_parameters(_subject, 'dropped', [player])
- assert_eq(_subject.flag_state, Flag.FlagState.FLAG_STATE_DROPPED)
+ assert_eq(_subject.flag_state, Flag.FlagState.DROPPED)
player.free()
func test_that_on_stand_flag_drop_does_not_emit_signals_and_keeps_state() -> void:
var player : Player = PLAYER.instantiate()
_subject.drop(player)
assert_signal_not_emitted(_subject, 'dropped')
- assert_eq(_subject.flag_state, Flag.FlagState.FLAG_STATE_ON_STAND)
+ assert_eq(_subject.flag_state, Flag.FlagState.ON_STAND)
player.free()
func test_that_flag_drop_shows_mesh() -> void: