game: add xp orbs
This commit is contained in:
@@ -2,3 +2,24 @@ class_name XPOrb
|
||||
extends Node2D
|
||||
|
||||
@export var value: float
|
||||
@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
|
||||
|
Reference in New Issue
Block a user