mirror of
https://github.com/Steffo99/hella-farm.git
synced 2024-11-25 09:34:24 +00:00
22 lines
516 B
GDScript
22 lines
516 B
GDScript
@icon("res://behaviours/move_towards.svg")
|
|
extends Node2D
|
|
class_name MoveTowards
|
|
|
|
|
|
## A node emitting the [signal move] signal each physics timestep to move towards the position of [field target].
|
|
|
|
|
|
signal move(norm: Vector2)
|
|
|
|
|
|
@export var target: Node2D = null
|
|
|
|
|
|
func _ready() -> void:
|
|
if target == null:
|
|
Log.w(self, "No target is set, no signals will be emitted.")
|
|
|
|
func _physics_process(_delta: float) -> void:
|
|
var gap = target.global_position - global_position
|
|
var norm = gap.normalized()
|
|
move.emit(norm)
|