22 lines
640 B
GDScript
22 lines
640 B
GDScript
extends RigidBody3D
|
|
class_name Gold
|
|
|
|
var amount = 1
|
|
var follow_target
|
|
var spawn_out = false
|
|
const SPAWN_OUT_SIZE = 4.0
|
|
const SPAWN_OUT_HEIGHT = 14.0
|
|
|
|
func _process(delta: float) -> void:
|
|
if follow_target != null:
|
|
if spawn_out:
|
|
follow_target.gold += amount
|
|
queue_free()
|
|
else:
|
|
if global_position.distance_to(follow_target.global_position) < .5:
|
|
spawn_out = true
|
|
else:
|
|
var direction_to_player = global_position.direction_to(follow_target.global_position)
|
|
var distance_to_player = global_position.distance_to(follow_target.global_position)
|
|
linear_velocity = direction_to_player * (5 + distance_to_player * 3)
|