20 lines
621 B
C#
20 lines
621 B
C#
using Godot;
|
|
using System.Linq;
|
|
|
|
public partial class MeleeEnemy : BasicEnemy
|
|
{
|
|
[Export]
|
|
private float _speed = 0.4f;
|
|
|
|
public override void _PhysicsProcess(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();
|
|
Position = Position.MoveToward(target.Position, _speed * (float)delta);
|
|
LookAt(new Vector3(-target.Position.X, 0, -target.Position.Z), Vector3.Up);
|
|
}
|
|
}
|
|
} |