18 lines
511 B
C#
18 lines
511 B
C#
using Godot;
|
|
using System.Linq;
|
|
|
|
public partial class RangedEnemy : BasicEnemy
|
|
{
|
|
public override void _Process(double delta)
|
|
{
|
|
var players = GetTree().GetNodesInGroup("Player");
|
|
if (players.Any())
|
|
{
|
|
var convertedPlayers = players.Select(x => (Node3D)x);
|
|
var target = convertedPlayers.OrderBy(x => Position.DistanceTo(x.Position)).FirstOrDefault();
|
|
LookAt(target.Position, Vector3.Up);
|
|
Rotation = new Vector3(0, Rotation.Y, Rotation.Z);
|
|
}
|
|
}
|
|
}
|