Merge branch 'feat/flag-smoothing' into 'develop'

Make the Flag entity smooth as silk

See merge request open-fpsz/open-fpsz!71
This commit is contained in:
Squinty 2024-04-25 19:18:16 +00:00
commit 3671d29d13
7 changed files with 43 additions and 32 deletions

View file

@ -12,14 +12,13 @@
# #
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>. # along with this program. If not, see <https://www.gnu.org/licenses/>.
class_name FlagCarryComponent extends Node class_name FlagCarryComponent extends Node3D
## This component allows its entity to grab, carry and throw flags ## This component allows its entity to grab, carry and throw flags
## ##
## To work correctly the owner MUST set an attachment point for carried 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 ## and a sensor to detect when flags are within grab range
@export var max_throw_speed : float = 10.0 @export var max_throw_speed : float = 10.0
@export var attachment : Node3D
@export var sensor : Area3D @export var sensor : Area3D
@export var carrier : Player @export var carrier : Player
@ -28,24 +27,26 @@ var _carried_flag : Flag
func _ready() -> void: func _ready() -> void:
sensor.body_entered.connect(_sensor_on_body_entered) sensor.body_entered.connect(_sensor_on_body_entered)
func _process(_delta : float) -> void: func _physics_process(_delta : float) -> void:
if _is_carrying(): if _is_carrying():
_carried_flag.global_position = attachment.global_position _carried_flag.global_position = global_position
_carried_flag.global_rotation = attachment.global_rotation _carried_flag.global_rotation = global_rotation
func _grab(flag : Flag) -> void: func _grab(flag : Flag) -> void:
if not _is_carrying(): if not _is_carrying():
flag.grab(carrier) flag.grab(carrier)
_carried_flag = flag _carried_flag = flag
show()
func _release(inherited_velocity : Vector3, throw_speed : float) -> void: func _release(inherited_velocity : Vector3, throw_speed : float) -> void:
if _is_carrying(): if _is_carrying():
_carried_flag.drop() _carried_flag.drop()
_carried_flag.rotation_degrees.x = 0.0 _carried_flag.rotation_degrees.x = 0.0
_carried_flag.linear_velocity = inherited_velocity + (attachment.global_basis.z * throw_speed) _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 # Throw the flag from some distance in front of the player to avoid regrabbing mid-air
_carried_flag.global_position = _carried_flag.global_position + (attachment.global_basis.z * 1.5) _carried_flag.global_position = _carried_flag.global_position + (global_basis.z * 1.5)
_carried_flag = null _carried_flag = null
hide()
func _is_carrying() -> bool: func _is_carrying() -> bool:
return _carried_flag != null return _carried_flag != null

View file

@ -2,5 +2,5 @@
[ext_resource type="Script" path="res://components/flag_carry_component.gd" id="1_b6ee8"] [ext_resource type="Script" path="res://components/flag_carry_component.gd" id="1_b6ee8"]
[node name="FlagCarryComponent" type="Node"] [node name="FlagCarryComponent" type="Node3D"]
script = ExtResource("1_b6ee8") script = ExtResource("1_b6ee8")

View file

@ -9,12 +9,14 @@ signal regrabbed
signal dropped signal dropped
var last_carrier : Player = null var last_carrier : Player = null
@onready var _mesh : Node = $Smoothing/Mesh
func can_be_grabbed() -> bool: func can_be_grabbed() -> bool:
return flag_state != FlagState.FLAG_STATE_TAKEN return flag_state != FlagState.FLAG_STATE_TAKEN
func grab(grabber : Player) -> void: func grab(grabber : Player) -> void:
if flag_state != FlagState.FLAG_STATE_TAKEN: if flag_state != FlagState.FLAG_STATE_TAKEN:
_mesh.hide()
flag_state = FlagState.FLAG_STATE_TAKEN flag_state = FlagState.FLAG_STATE_TAKEN
if (last_carrier == null) or (grabber != last_carrier): if (last_carrier == null) or (grabber != last_carrier):
grabbed.emit(grabber) grabbed.emit(grabber)
@ -24,6 +26,7 @@ func grab(grabber : Player) -> void:
func drop() -> void: func drop() -> void:
if flag_state == FlagState.FLAG_STATE_TAKEN: if flag_state == FlagState.FLAG_STATE_TAKEN:
_mesh.show()
flag_state = FlagState.FLAG_STATE_DROPPED flag_state = FlagState.FLAG_STATE_DROPPED
dropped.emit() dropped.emit()

View file

@ -1,6 +1,7 @@
[gd_scene load_steps=7 format=3 uid="uid://c88l3h0ph00c7"] [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://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://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="PackedScene" uid="uid://bcgkc5fhhyauv" path="res://entities/flag/waypoint.tscn" id="3_tu6jg"]
@ -20,6 +21,9 @@ properties/1/replication_mode = 1
properties/2/path = NodePath(".:flag_state") properties/2/path = NodePath(".:flag_state")
properties/2/spawn = true properties/2/spawn = true
properties/2/replication_mode = 2 properties/2/replication_mode = 2
properties/3/path = NodePath("Smoothing/Mesh:visible")
properties/3/spawn = true
properties/3/replication_mode = 2
[node name="Flag" type="RigidBody3D"] [node name="Flag" type="RigidBody3D"]
collision_layer = 8 collision_layer = 8
@ -34,9 +38,6 @@ center_of_mass = Vector3(0, 0.5, 0)
continuous_cd = true continuous_cd = true
script = ExtResource("1_y7d3d") script = ExtResource("1_y7d3d")
[node name="Mesh" parent="." instance=ExtResource("2_i78em")]
transform = Transform3D(0.33, 0, 0, 0, 0.421029, 0, 0, 0, 0.33, 0, 0.0744106, 0)
[node name="CollisionShape3D" type="CollisionShape3D" parent="."] [node name="CollisionShape3D" type="CollisionShape3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0) transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0)
shape = SubResource("BoxShape3D_fkf1k") shape = SubResource("BoxShape3D_fkf1k")
@ -44,8 +45,14 @@ shape = SubResource("BoxShape3D_fkf1k")
[node name="MultiplayerSynchronizer" type="MultiplayerSynchronizer" parent="."] [node name="MultiplayerSynchronizer" type="MultiplayerSynchronizer" parent="."]
replication_config = SubResource("SceneReplicationConfig_lpijf") replication_config = SubResource("SceneReplicationConfig_lpijf")
[node name="WaypointAttachment" type="Marker3D" parent="."] [node name="Smoothing" type="Node3D" parent="."]
script = ExtResource("2_es4ce")
[node name="Waypoint" parent="WaypointAttachment" node_paths=PackedStringArray("attach_point", "flag") instance=ExtResource("3_tu6jg")] [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("..") attach_point = NodePath("..")
flag = 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)

View file

@ -49,10 +49,9 @@ enum PlayerState { PLAYER_ALIVE, PLAYER_DEAD }
@onready var animation_player : AnimationPlayer = $AnimationPlayer @onready var animation_player : AnimationPlayer = $AnimationPlayer
@onready var health_component : Area3D = $HealthComponent @onready var health_component : Area3D = $HealthComponent
@onready var collision_shape : CollisionShape3D = $CollisionShape3D @onready var collision_shape : CollisionShape3D = $CollisionShape3D
@onready var flag_carry_component : FlagCarryComponent = $FlagCarryComponent @onready var flag_carry_component : FlagCarryComponent = $Smoothing/SpringArm3D/FlagCarryComponent
@onready var spring_arm_height : float = $Smoothing/SpringArm3D.position.y @onready var spring_arm_height : float = $Smoothing/SpringArm3D.position.y
@onready var _original_weapon_transform : Transform3D = weapon.transform @onready var _original_weapon_transform : Transform3D = weapon.transform
@onready var flag_carry_attachment : Node3D = $Smoothing/SpringArm3D/FlagCarryAttachment
@onready var tp_player : Vanguard = $Smoothing/ThirdPerson/PlayerMesh @onready var tp_player : Vanguard = $Smoothing/ThirdPerson/PlayerMesh
@onready var _game_settings : Settings = get_node("/root/GlobalSettings") @onready var _game_settings : Settings = get_node("/root/GlobalSettings")
@ -86,7 +85,6 @@ func _ready() -> void:
camera.fov = _game_settings.fov camera.fov = _game_settings.fov
# set the spring arm translation to be about head height level # set the spring arm translation to be about head height level
$Smoothing/SpringArm3D.transform = Transform3D().translated(Vector3(0, collision_shape.shape.height / 2, 0) * 0.9) $Smoothing/SpringArm3D.transform = Transform3D().translated(Vector3(0, collision_shape.shape.height / 2, 0) * 0.9)
flag_carry_attachment.hide()
$Smoothing.remove_child($Smoothing/ThirdPerson) $Smoothing.remove_child($Smoothing/ThirdPerson)
else: else:

View file

@ -1,4 +1,4 @@
[gd_scene load_steps=18 format=3 uid="uid://cbhx1xme0sb7k"] [gd_scene load_steps=19 format=3 uid="uid://cbhx1xme0sb7k"]
[ext_resource type="Script" path="res://entities/player/player.gd" id="1_mk68k"] [ext_resource type="Script" path="res://entities/player/player.gd" id="1_mk68k"]
[ext_resource type="PackedScene" uid="uid://drbefw6akui2v" path="res://entities/player/assets/vanguard.tscn" id="2_beyex"] [ext_resource type="PackedScene" uid="uid://drbefw6akui2v" path="res://entities/player/assets/vanguard.tscn" id="2_beyex"]
@ -9,6 +9,7 @@
[ext_resource type="Script" path="res://entities/player/player_input.gd" id="6_ymcrr"] [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"] [ext_resource type="PackedScene" uid="uid://dsysi2rd3bu76" path="res://interfaces/hud/iffs/iff.tscn" id="7_8hc80"]
[ext_resource type="PackedScene" uid="uid://2t8ql8pkxv6c" path="res://components/flag_carry_component.tscn" id="7_e7s1a"] [ext_resource type="PackedScene" uid="uid://2t8ql8pkxv6c" path="res://components/flag_carry_component.tscn" id="7_e7s1a"]
[ext_resource type="PackedScene" uid="uid://d3l7fvbdg6m5g" path="res://entities/flag/assets/flag.glb" id="9_fce2y"]
[ext_resource type="Script" path="res://addons/smoothing/smoothing.gd" id="11_k330l"] [ext_resource type="Script" path="res://addons/smoothing/smoothing.gd" id="11_k330l"]
[sub_resource type="PhysicsMaterial" id="PhysicsMaterial_clur0"] [sub_resource type="PhysicsMaterial" id="PhysicsMaterial_clur0"]
@ -130,11 +131,6 @@ shape = ExtResource("2_vjqny")
[node name="CollisionShape3D" type="CollisionShape3D" parent="HealthComponent"] [node name="CollisionShape3D" type="CollisionShape3D" parent="HealthComponent"]
shape = ExtResource("2_vjqny") shape = ExtResource("2_vjqny")
[node name="FlagCarryComponent" parent="." node_paths=PackedStringArray("attachment", "sensor", "carrier") instance=ExtResource("7_e7s1a")]
attachment = NodePath("../Smoothing/SpringArm3D/FlagCarryAttachment")
sensor = NodePath("../Sensor")
carrier = NodePath("..")
[node name="AnimationPlayer" type="AnimationPlayer" parent="."] [node name="AnimationPlayer" type="AnimationPlayer" parent="."]
libraries = { libraries = {
"": SubResource("AnimationLibrary_hg307") "": SubResource("AnimationLibrary_hg307")
@ -174,8 +170,14 @@ holder = NodePath("../../../..")
[node name="SpineIKTarget" type="Node3D" parent="Smoothing/SpringArm3D"] [node name="SpineIKTarget" type="Node3D" parent="Smoothing/SpringArm3D"]
transform = Transform3D(-1, 0, -8.74228e-08, 0, 1, 0, 8.74228e-08, 0, -1, 0, 0, 0) transform = Transform3D(-1, 0, -8.74228e-08, 0, 1, 0, 8.74228e-08, 0, -1, 0, 0, 0)
[node name="FlagCarryAttachment" type="Node3D" parent="Smoothing/SpringArm3D"] [node name="FlagCarryComponent" parent="Smoothing/SpringArm3D" node_paths=PackedStringArray("sensor", "carrier") instance=ExtResource("7_e7s1a")]
transform = Transform3D(-1, 0, -8.74228e-08, 0, 1, 0, 8.74228e-08, 0, -1, 0, -0.620994, -0.287925) transform = Transform3D(-1, 0, -8.74228e-08, 0, 1, 0, 8.74228e-08, 0, -1, 0, 0, 0.150603)
visible = false
sensor = NodePath("../../../Sensor")
carrier = NodePath("../../..")
[node name="FlagMesh" parent="Smoothing/SpringArm3D/FlagCarryComponent" instance=ExtResource("9_fce2y")]
transform = Transform3D(0.5, 0, 0, 0, 0.5, 0, 0, 0, 0.5, 0, -0.602515, 0)
[node name="ThirdPerson" type="Node3D" parent="Smoothing"] [node name="ThirdPerson" type="Node3D" parent="Smoothing"]