2024-04-15 23:57:22 +00:00
|
|
|
@icon("res://behaviours/move_towards.svg")
|
2024-04-14 16:20:08 +00:00
|
|
|
extends Node2D
|
|
|
|
class_name MoveTowards
|
|
|
|
|
|
|
|
|
2024-04-15 23:57:22 +00:00
|
|
|
## A node emitting the [signal move] signal each physics timestep to move towards the position of [field target].
|
2024-04-14 16:20:08 +00:00
|
|
|
|
|
|
|
|
2024-04-15 23:57:22 +00:00
|
|
|
signal move(norm: Vector2)
|
2024-04-14 16:20:08 +00:00
|
|
|
|
|
|
|
|
2024-04-15 23:57:22 +00:00
|
|
|
@export var target: Node2D = null
|
2024-04-14 16:20:08 +00:00
|
|
|
|
|
|
|
|
2024-04-15 23:57:22 +00:00
|
|
|
func _ready() -> void:
|
|
|
|
if target == null:
|
|
|
|
Log.w(self, "No target is set, no signals will be emitted.")
|
2024-04-14 16:20:08 +00:00
|
|
|
|
2024-04-15 23:57:22 +00:00
|
|
|
func _physics_process(_delta: float) -> void:
|
|
|
|
var gap = target.global_position - global_position
|
|
|
|
var norm = gap.normalized()
|
|
|
|
move.emit(norm)
|