31 lines
762 B
GDScript
31 lines
762 B
GDScript
class_name PickupBase
|
|
extends Node2D
|
|
|
|
@export var max_speed: float = 100.0
|
|
@export var min_speed: float = 10.0
|
|
|
|
var player: Player
|
|
|
|
|
|
func _ready() -> void:
|
|
player = get_tree().get_first_node_in_group(GlobalConst.GROUP_PLAYER)
|
|
|
|
|
|
func _physics_process(delta: float) -> void:
|
|
if not player:
|
|
return
|
|
|
|
var to_player = player.global_position - global_position
|
|
var dist = to_player.length()
|
|
var attract_radius = player.player_stats.get_final("pickup_radius", player.modifiers)
|
|
if dist < 4:
|
|
return
|
|
if dist < attract_radius:
|
|
var dir = to_player.normalized()
|
|
var speed = lerp(min_speed, max_speed, (attract_radius - dist) / attract_radius)
|
|
global_position += dir * speed * delta
|
|
|
|
|
|
func pickup() -> void:
|
|
push_error("%s did not implement pickup()" % self)
|