mirror of
https://gitlab.com/open-fpsz/open-fpsz.git
synced 2026-04-29 08:15:35 +00:00
35 lines
858 B
GDScript
35 lines
858 B
GDScript
class_name FlagCarryComponent extends Node
|
|
|
|
@export var throw_velocity : float = 10.0
|
|
@export var attachment : Node3D
|
|
@export var sensor : Area3D
|
|
|
|
var _carried_flag : Flag
|
|
|
|
func _ready():
|
|
sensor.body_entered.connect(_sensor_on_body_entered)
|
|
|
|
func _process(_delta):
|
|
if _is_carrying():
|
|
_carried_flag.global_position = attachment.global_position
|
|
_carried_flag.global_rotation = attachment.global_rotation
|
|
|
|
@rpc("call_local")
|
|
func _grab(flag : Flag):
|
|
if not _is_carrying():
|
|
flag.grab()
|
|
_carried_flag = flag
|
|
|
|
func throw():
|
|
if _is_carrying():
|
|
_carried_flag.drop()
|
|
_carried_flag.linear_velocity = attachment.global_basis.z * throw_velocity
|
|
_carried_flag.rotation_degrees.x = 0.0
|
|
_carried_flag = null
|
|
|
|
func _is_carrying() -> bool:
|
|
return _carried_flag != null
|
|
|
|
func _sensor_on_body_entered(collider):
|
|
if collider is Flag:
|
|
_grab.rpc(collider)
|