From 323c5f1c99e80514ce3cb124f4eccb59782111bc Mon Sep 17 00:00:00 2001 From: Squinty Date: Thu, 25 Apr 2024 19:18:15 +0000 Subject: [PATCH] Make the Flag entity smooth as silk --- components/flag_carry_component.gd | 15 ++++++++------- components/flag_carry_component.tscn | 2 +- entities/flag/flag.gd | 3 +++ entities/flag/flag.tscn | 21 ++++++++++++++------- entities/flag/waypoint.gd | 12 ++++++------ entities/player/player.gd | 4 +--- entities/player/player.tscn | 18 ++++++++++-------- 7 files changed, 43 insertions(+), 32 deletions(-) diff --git a/components/flag_carry_component.gd b/components/flag_carry_component.gd index 54eaeaa..021ac9c 100644 --- a/components/flag_carry_component.gd +++ b/components/flag_carry_component.gd @@ -12,14 +12,13 @@ # # You should have received a copy of the GNU General Public License # along with this program. If not, see . -class_name FlagCarryComponent extends Node +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 attachment : Node3D @export var sensor : Area3D @export var carrier : Player @@ -28,24 +27,26 @@ var _carried_flag : Flag func _ready() -> void: sensor.body_entered.connect(_sensor_on_body_entered) -func _process(_delta : float) -> void: +func _physics_process(_delta : float) -> void: if _is_carrying(): - _carried_flag.global_position = attachment.global_position - _carried_flag.global_rotation = attachment.global_rotation + _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) -> void: if _is_carrying(): _carried_flag.drop() _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 - _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 + hide() func _is_carrying() -> bool: return _carried_flag != null diff --git a/components/flag_carry_component.tscn b/components/flag_carry_component.tscn index ececd0e..17603b8 100644 --- a/components/flag_carry_component.tscn +++ b/components/flag_carry_component.tscn @@ -2,5 +2,5 @@ [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") diff --git a/entities/flag/flag.gd b/entities/flag/flag.gd index 631b7f3..4f86225 100644 --- a/entities/flag/flag.gd +++ b/entities/flag/flag.gd @@ -9,12 +9,14 @@ signal regrabbed signal dropped var last_carrier : Player = null +@onready var _mesh : Node = $Smoothing/Mesh func can_be_grabbed() -> bool: return flag_state != FlagState.FLAG_STATE_TAKEN func grab(grabber : Player) -> void: if flag_state != FlagState.FLAG_STATE_TAKEN: + _mesh.hide() flag_state = FlagState.FLAG_STATE_TAKEN if (last_carrier == null) or (grabber != last_carrier): grabbed.emit(grabber) @@ -24,6 +26,7 @@ func grab(grabber : Player) -> void: func drop() -> void: if flag_state == FlagState.FLAG_STATE_TAKEN: + _mesh.show() flag_state = FlagState.FLAG_STATE_DROPPED dropped.emit() diff --git a/entities/flag/flag.tscn b/entities/flag/flag.tscn index cf67430..c83cdd5 100644 --- a/entities/flag/flag.tscn +++ b/entities/flag/flag.tscn @@ -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://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"] @@ -20,6 +21,9 @@ properties/1/replication_mode = 1 properties/2/path = NodePath(".:flag_state") properties/2/spawn = true 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"] collision_layer = 8 @@ -34,9 +38,6 @@ center_of_mass = Vector3(0, 0.5, 0) continuous_cd = true 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="."] transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0) shape = SubResource("BoxShape3D_fkf1k") @@ -44,8 +45,14 @@ shape = SubResource("BoxShape3D_fkf1k") [node name="MultiplayerSynchronizer" type="MultiplayerSynchronizer" parent="."] 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("..") -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) diff --git a/entities/flag/waypoint.gd b/entities/flag/waypoint.gd index a56a668..7911110 100644 --- a/entities/flag/waypoint.gd +++ b/entities/flag/waypoint.gd @@ -1,15 +1,15 @@ # 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 @@ -32,15 +32,15 @@ func _process(_delta : float) -> void: 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 diff --git a/entities/player/player.gd b/entities/player/player.gd index f490b3a..fcf9ad4 100644 --- a/entities/player/player.gd +++ b/entities/player/player.gd @@ -49,10 +49,9 @@ enum PlayerState { PLAYER_ALIVE, PLAYER_DEAD } @onready var animation_player : AnimationPlayer = $AnimationPlayer @onready var health_component : Area3D = $HealthComponent @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 _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 _game_settings : Settings = get_node("/root/GlobalSettings") @@ -86,7 +85,6 @@ func _ready() -> void: camera.fov = _game_settings.fov # 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) - flag_carry_attachment.hide() $Smoothing.remove_child($Smoothing/ThirdPerson) else: diff --git a/entities/player/player.tscn b/entities/player/player.tscn index e90e0fb..10ff523 100644 --- a/entities/player/player.tscn +++ b/entities/player/player.tscn @@ -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="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="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://d3l7fvbdg6m5g" path="res://entities/flag/assets/flag.glb" id="9_fce2y"] [ext_resource type="Script" path="res://addons/smoothing/smoothing.gd" id="11_k330l"] [sub_resource type="PhysicsMaterial" id="PhysicsMaterial_clur0"] @@ -130,11 +131,6 @@ shape = ExtResource("2_vjqny") [node name="CollisionShape3D" type="CollisionShape3D" parent="HealthComponent"] 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="."] libraries = { "": SubResource("AnimationLibrary_hg307") @@ -174,8 +170,14 @@ holder = NodePath("../../../..") [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) -[node name="FlagCarryAttachment" type="Node3D" parent="Smoothing/SpringArm3D"] -transform = Transform3D(-1, 0, -8.74228e-08, 0, 1, 0, 8.74228e-08, 0, -1, 0, -0.620994, -0.287925) +[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, 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"]