Fix collision with player
This commit is contained in:
@@ -5,6 +5,9 @@ public partial class MeleeEnemy : BasicEnemy
|
||||
{
|
||||
[Export]
|
||||
private float _speed = 0.4f;
|
||||
private bool _targetingPlayer = false;
|
||||
[Export]
|
||||
private double _distanceToPlayer = 3;
|
||||
|
||||
public override void _PhysicsProcess(double delta)
|
||||
{
|
||||
@@ -13,8 +16,12 @@ public partial class MeleeEnemy : BasicEnemy
|
||||
{
|
||||
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(-target.Position, Vector3.Up);
|
||||
if (_targetingPlayer || Position.DistanceTo(target.Position) < _distanceToPlayer)
|
||||
{
|
||||
Position = Position.MoveToward(target.Position, _speed * (float)delta);
|
||||
LookAt(-target.Position, Vector3.Up);
|
||||
_targetingPlayer = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user