25 lines
913 B
GDScript
25 lines
913 B
GDScript
extends Node3D
|
|
|
|
@onready var flow_field_navigation: FlowFieldNav = %FlowFieldNavigation
|
|
|
|
@export var move_speed = 3
|
|
|
|
# Called when the node enters the scene tree for the first time.
|
|
func _ready() -> void:
|
|
pass # Replace with function body.
|
|
|
|
|
|
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
|
func _process(delta: float) -> void:
|
|
DebugDraw3D.draw_sphere(position, .5)
|
|
var cell = flow_field_navigation.get_cell_from_pos(position)
|
|
|
|
if cell.flow_direction.length() > 0.0:
|
|
# Normalisierte Bewegung in Flow-Richtung
|
|
var movement = cell.flow_direction.normalized() * move_speed * delta
|
|
global_transform.origin += movement # Position aktualisierennormalized() * speed
|
|
|
|
# Rotation: Gegner schaut in Bewegungsrichtung (XZ-Ebene)
|
|
var target_rotation = Quaternion(Vector3.UP, atan2(-cell.flow_direction.x, -cell.flow_direction.z))
|
|
global_transform.basis = Basis(target_rotation)
|