Fix hit detection
This commit is contained in:
@@ -1,9 +1,10 @@
|
||||
using Godot;
|
||||
using System.Linq;
|
||||
|
||||
public partial class MeleeEnemy : CharacterBody3D
|
||||
public partial class MeleeEnemy : BasicEnemy
|
||||
{
|
||||
private float _speed = 1.0f;
|
||||
[Export]
|
||||
private float _speed = 0.4f;
|
||||
|
||||
public override void _PhysicsProcess(double delta)
|
||||
{
|
||||
@@ -12,9 +13,22 @@ public partial class MeleeEnemy : CharacterBody3D
|
||||
{
|
||||
var convertedPlayers = players.Select(x => (Node3D)x);
|
||||
var target = convertedPlayers.OrderBy(x => Position.DistanceTo(x.Position)).FirstOrDefault();
|
||||
GD.Print(Position.DirectionTo(target.Position));
|
||||
Position = Position.MoveToward(target.Position, _speed * (float)delta);
|
||||
MoveAndSlide();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public partial class BasicEnemy : CharacterBody3D
|
||||
{
|
||||
public void OnHit(Node3D node)
|
||||
{
|
||||
QueueFree();
|
||||
}
|
||||
|
||||
private void DebugOnHit()
|
||||
{
|
||||
var node = new Node3D();
|
||||
OnHit(node);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user