added: enemy target acquisition, better pathfinding, moved combat reference to unit
This commit is contained in:
@@ -32,7 +32,7 @@ namespace Reset.Units{
|
||||
relatedGraph.collision.diameter = 3f;
|
||||
|
||||
AstarPath.active.Scan(relatedGraph);
|
||||
|
||||
|
||||
GetComponent<ProceduralGraphMover>().graph = relatedGraph;
|
||||
}
|
||||
|
||||
@@ -59,6 +59,39 @@ namespace Reset.Units{
|
||||
// Update is called once per frame
|
||||
void Update(){
|
||||
Draw.WireCylinder(transform.position, transform.position + Vector3.up * 7f, radius);
|
||||
|
||||
if (PlayerIsInRange()) {
|
||||
SetPlayerAsTarget();
|
||||
}
|
||||
}
|
||||
|
||||
GameObject PlayerIsInRange(){
|
||||
// TODO: Make compatible with all players
|
||||
Vector3 playerPos = PlayerManager.Player.transform.position;
|
||||
|
||||
// Skip checking and return null/false if the player is nowhere near the spawn
|
||||
if (Vector3.Distance(playerPos, transform.position) < radius * 1.5f) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// If they are in range, check if the player is close enough to either an enemy or the spawn center
|
||||
if (Vector3.Distance(playerPos, transform.position) < radius * .33f) {
|
||||
return PlayerManager.Player;
|
||||
}
|
||||
|
||||
foreach (GameObject thisEnemy in enemies) {
|
||||
if (Vector3.Distance(playerPos, thisEnemy.transform.position) < radius / 2f) {
|
||||
return PlayerManager.Player;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
void SetPlayerAsTarget(){
|
||||
foreach (GameObject thisEnemy in enemies) {
|
||||
thisEnemy.GetComponent<EnemyCombat>().SetNewTarget(PlayerManager.Player);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user