21 lines
635 B
GDScript3
21 lines
635 B
GDScript3
|
extends Node3D
|
||
|
|
||
|
|
||
|
# 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:
|
||
|
var closest: Node3D
|
||
|
var least_dist = INF
|
||
|
for p: Node3D in get_tree().get_nodes_in_group('players'):
|
||
|
var dist = global_position.distance_to(p.global_position)
|
||
|
if dist < least_dist:
|
||
|
least_dist = dist
|
||
|
closest = p
|
||
|
|
||
|
if closest:
|
||
|
look_at(closest.global_position * Vector3(1, 0, 1) + Vector3(0, 1, 0), Vector3.UP, true)
|