Make the Flag entity smooth as silk

This commit is contained in:
Squinty 2024-04-25 19:18:15 +00:00
parent 0977336f8c
commit 86d90730c8
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
# 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
##
## 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

View file

@ -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")