mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-08 15:15:54 +00:00
Enemy strafing
This commit is contained in:
parent
a18dc11eb3
commit
b35772f519
6 changed files with 112 additions and 16 deletions
|
|
@ -60,18 +60,20 @@ public partial class PlayerDetectionModule : Area2D
|
|||
//if (_cachedPlayer == null) return false;
|
||||
if (!GameManager.Instance.PlayerPosition.HasValue) return false;
|
||||
|
||||
var spaceState = GetWorld2D().DirectSpaceState;
|
||||
var found = HasLineOfSight(this.GlobalPosition, GameManager.Instance.PlayerPosition.Value);
|
||||
|
||||
// It needs to use its own collision mask because it's detecting obstacles rather than the player
|
||||
var query = PhysicsRayQueryParameters2D.Create(this.GlobalPosition, GameManager.Instance.PlayerPosition.Value, ObstaclesCollisionMask,
|
||||
[GetRid()]);
|
||||
//query.CollideWithBodies = true;
|
||||
//query.CollideWithAreas = true;
|
||||
// var query = PhysicsRayQueryParameters2D.Create(this.GlobalPosition, _cachedPlayer.GlobalPosition, CollisionMask, new Array<Rid> { GetRid() });
|
||||
var result = spaceState.IntersectRay(query);
|
||||
|
||||
// If count is 0 then the player is in sight, otherwise there is level geometry in the way
|
||||
var found = result.Count == 0;
|
||||
// var spaceState = GetWorld2D().DirectSpaceState;
|
||||
//
|
||||
// // It needs to use its own collision mask because it's detecting obstacles rather than the player
|
||||
// var query = PhysicsRayQueryParameters2D.Create(this.GlobalPosition, GameManager.Instance.PlayerPosition.Value, ObstaclesCollisionMask,
|
||||
// [GetRid()]);
|
||||
// //query.CollideWithBodies = true;
|
||||
// //query.CollideWithAreas = true;
|
||||
// // var query = PhysicsRayQueryParameters2D.Create(this.GlobalPosition, _cachedPlayer.GlobalPosition, CollisionMask, new Array<Rid> { GetRid() });
|
||||
// var result = spaceState.IntersectRay(query);
|
||||
//
|
||||
// // If count is 0 then the player is in sight, otherwise there is level geometry in the way
|
||||
// var found = result.Count == 0;
|
||||
if (found)
|
||||
{
|
||||
LastKnownPlayerPosition = GameManager.Instance.PlayerPosition;
|
||||
|
|
@ -92,4 +94,22 @@ public partial class PlayerDetectionModule : Area2D
|
|||
EmitSignal(SignalName.PlayerOutOfRange);
|
||||
//PlayerInActiveArea = false;
|
||||
}
|
||||
|
||||
public bool HasLineOfSight(Vector2 startPos, Vector2 endPos)
|
||||
{
|
||||
var spaceState = GetWorld2D().DirectSpaceState;
|
||||
|
||||
// It needs to use its own collision mask because it's detecting obstacles rather than the player
|
||||
var query = PhysicsRayQueryParameters2D.Create(startPos, endPos, ObstaclesCollisionMask,
|
||||
[GetRid()]);
|
||||
//query.CollideWithBodies = true;
|
||||
//query.CollideWithAreas = true;
|
||||
// var query = PhysicsRayQueryParameters2D.Create(this.GlobalPosition, _cachedPlayer.GlobalPosition, CollisionMask, new Array<Rid> { GetRid() });
|
||||
var result = spaceState.IntersectRay(query);
|
||||
|
||||
// If count is 0 then the player is in sight, otherwise there is level geometry in the way
|
||||
var found = result.Count == 0;
|
||||
|
||||
return found;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue