Fix collision with player
This commit is contained in:
@@ -7,6 +7,8 @@ public partial class FireAtPlayer : Timer
|
||||
private BasicEnemy _enemy;
|
||||
[Export]
|
||||
private PackedScene _fireProjectile;
|
||||
[Export]
|
||||
private double _distanceToPlayer = 3;
|
||||
|
||||
public void OnFireAtPlayer()
|
||||
{
|
||||
@@ -15,10 +17,13 @@ public partial class FireAtPlayer : Timer
|
||||
{
|
||||
var convertedPlayers = players.Select(x => (Node3D)x);
|
||||
var target = convertedPlayers.OrderBy(x => _enemy.Position.DistanceTo(x.Position)).FirstOrDefault();
|
||||
var projectile = _fireProjectile.Instantiate<Projectile>() as EnemyBullet;
|
||||
projectile.Rotation = new Vector3(0, _enemy.Rotation.Y, 0);
|
||||
projectile.Position = _enemy.Position;
|
||||
AddChild(projectile);
|
||||
if (_enemy.Position.DistanceTo(target.Position) < _distanceToPlayer)
|
||||
{
|
||||
var projectile = _fireProjectile.Instantiate<Projectile>() as EnemyBullet;
|
||||
projectile.Rotation = new Vector3(0, _enemy.Rotation.Y, 0);
|
||||
projectile.Position = _enemy.Position;
|
||||
AddChild(projectile);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user