Skip to content

Commit

Permalink
AI Finetuning
Browse files Browse the repository at this point in the history
  • Loading branch information
AdronTech committed Jan 22, 2017
1 parent c32557d commit 5cfa1f4
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 12 deletions.
Binary file modified GGJ17/Assets/Scene/Marky.unity
Binary file not shown.
7 changes: 4 additions & 3 deletions GGJ17/Assets/Script/AttackBehaviour.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ void Start () {
public void startAttack(Transform target)
{
this.target = target;
lr.enabled = true;
}

void Update()
{
lr.enabled = target != null;
{

if (lr.enabled)
if (lr.enabled && target)
{
Vector3[] positions = new Vector3[2];

Expand All @@ -43,6 +43,7 @@ void Update()

public void stopAttack()
{
lr.enabled = false;
target = null;
}

Expand Down
16 changes: 7 additions & 9 deletions GGJ17/Assets/Script/KingBehaviour.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ public class KingBehaviour : MonoBehaviour {
public GameObject soldierPre;
public int size;

private List<Transform> possibleTargets;

private List<MyPhysics> army;

private MyPhysics my;
Expand All @@ -24,7 +22,6 @@ void Awake () {
mySeek = GetComponent<SeekBehaviour>();

army = new List<MyPhysics>();
possibleTargets = new List<Transform>();

state = KingState.Seeking;

Expand Down Expand Up @@ -78,6 +75,8 @@ IEnumerator scanForTarget()
{
yield return new WaitUntil(() => state == KingState.Seeking);

List<Transform> possibleTargets = new List<Transform>();

foreach (AbstractBaseBuilding a in FindObjectsOfType<AbstractBaseBuilding>())
{
if (a.neighbors[AbstractBuildingBlock.down] && a.neighbors[AbstractBuildingBlock.down].tag == "Ground")
Expand All @@ -92,7 +91,6 @@ IEnumerator scanForTarget()
else
{
Debug.DrawLine(my.pos, a.transform.position, Color.blue);
if (possibleTargets.Contains(a.transform)) possibleTargets.Remove(a.transform);
}
}
}
Expand Down Expand Up @@ -141,7 +139,7 @@ IEnumerator stateMachineManager()
case KingState.Seeking:
if (!mySeek.target) break;

if (Mathf.Abs(my.pos.x - mySeek.target.position.x) <= attackRange || Mathf.Abs(my.pos.z - mySeek.target.position.z) <= attackRange)
if (Mathf.Abs(my.pos.x - mySeek.target.position.x) <= attackRange && Mathf.Abs(my.pos.z - mySeek.target.position.z) <= attackRange)
{
state = KingState.Attack;
mySeek.stop();
Expand All @@ -158,14 +156,14 @@ IEnumerator stateMachineManager()
case KingState.Attack:
if (!mySeek.target)
{
state = KingState.Seeking;
mySeek.start();

foreach (MyPhysics soldier in army)
{
AttackBehaviour ah = soldier.GetComponent<AttackBehaviour>();
if (ah) ah.startAttack(mySeek.target);
if (ah) ah.stopAttack();
}
mySeek.start();
state = KingState.Seeking;
Debug.Log("Destroyed");
}

break;
Expand Down
File renamed without changes.
File renamed without changes.
Binary file modified GGJ17/ProjectSettings/TagManager.asset
Binary file not shown.

0 comments on commit 5cfa1f4

Please sign in to comment.