1
Fork 0
mirror of https://github.com/Steffo99/hella-farm.git synced 2024-11-25 09:34:24 +00:00
hella-farm/behaviours/move_towards.gd
2024-04-17 05:29:45 +02:00

38 lines
722 B
GDScript

extends Move
class_name MoveTowards
## A [Move] that moves towards the [field position] of a [field target].
signal changed_target(new: Node2D)
@export var speed: float = 100.0
@export var target: Node2D = null:
get:
return target
set(value):
target = value
changed_target.emit(value)
func set_target(value: Node2D) -> void:
target = value
func clear_target() -> void:
target = null
func _physics_process(delta: float) -> void:
if enabled:
if target:
var gap = target.global_position - global_position
var norm = gap.normalized()
move.emit(norm * delta * speed)
else:
move.emit(Vector2.ZERO)
func _on_changed_target(new: Node2D) -> void:
Log.p(self, "Changed target to: %s" % new)