@@ -0,0 +1,38 @@
using UnityEngine;
using System.Collections;

public class Expel : MonoBehaviour {

public float forceAmount;
public GameObject player;
public Rigidbody rb;

void Awake ()

{
player = GameObject.FindGameObjectWithTag ("Player");
}

void Update()
{
bool down = Input.GetKeyDown (KeyCode.Space);

if (down) {
forceAmount = 2;
} else {
forceAmount = 0;
}

float distance = (rb.transform.position - player.transform.position).magnitude;

if (distance <= 4) {
Vector3 direction = (rb.transform.position - player.transform.position).normalized;
rb.AddForce(direction * forceAmount);
}

}




}
@@ -14,7 +14,11 @@ public class HP : MonoBehaviour {

void Update() {
if (hitpoints == 0) {
this.Friendly.SetActive(false);
Friendly.GetComponent<Rigidbody>().constraints = RigidbodyConstraints.FreezePositionX | RigidbodyConstraints.FreezePositionZ | RigidbodyConstraints.FreezeRotationX | RigidbodyConstraints.FreezeRotationZ;
Friendly.GetComponent<Rigidbody>().useGravity = true;
Destroy (GetComponent<flock>());
Friendly.tag = "Untagged";
Destroy (Friendly, 3);
}
}

@@ -0,0 +1,39 @@
using UnityEngine;
using System.Collections;

public class Map : MonoBehaviour {

public GameObject hexPrefab;
public int width = 50;
public int depth = 40;

float offset = 0.89f;


void Start() {
for (int x = 0; x < width; x=(x+2)){
for (int z = 0; z < depth; z++)
{
float xPos = x;

if ( z % 2 == 1) {
xPos = xPos+offset;
}

GameObject hex_obj =(GameObject)Instantiate(hexPrefab, new Vector3(xPos, 0, z*2*offset), Quaternion.identity);
hex_obj.name = "Hex_#_" + x + "_" + z;

hex_obj.transform.SetParent(this.transform, worldPositionStays:false);
}
}

}




// Update is called once per frame
void Update () {

}
}
@@ -2,66 +2,32 @@
using System.Collections;

public class flock : MonoBehaviour {

public float speed = 1f;
float rotationSpeed = 2.0f;
Vector3 averageHeading;
Vector3 averagePosition;
float neighborDistance = 1.0f;


void Start () {
}

void Update () {
if(Random.Range(0,5) < 1)
ApplyRules();

transform.Translate(0, 0, Time.deltaTime * speed);
}

void ApplyRules() {
GameObject[] flock;
flock = globalFlock.allFriendlies;

Vector3 vcenter = Vector3.zero;
Vector3 vavoid = Vector3.zero;
float gSpeed = 0.1f;

Vector3 goalPos = globalFlock.goalPos;

float dist;

int flockSize = 0;
foreach (GameObject friendly in flock) {
if (friendly != this.gameObject) {
dist = Vector3.Distance(friendly.transform.position,this.transform.position);

if(dist <= neighborDistance) {
vcenter += friendly.transform.position;
flockSize++;
}

if(dist < 1.0f) {
vavoid = vavoid + (this.transform.position - friendly.transform.position);
}

flock anotherFlock = friendly.GetComponent<flock>();
gSpeed = gSpeed + anotherFlock.speed;
}
}

public GameObject Friendly;
private GameObject Leader;
public GameObject[] friendlies;
private Transform target;


if (flockSize > 0) {
vcenter = vcenter/flockSize + (goalPos - this.transform.position);
speed = gSpeed/flockSize;

Vector3 direction = (vcenter + vavoid) - transform.position;
if (direction != Vector3.zero) {
transform.rotation = Quaternion.Lerp(transform.rotation,
Quaternion.LookRotation(direction),
rotationSpeed * Time.deltaTime);
}
void OnCollisionEnter(Collision collision) {
if (collision.gameObject.tag == "Player") {
if (null != GameObject.FindWithTag("Leader")) {
GameObject oldLeader = GameObject.FindWithTag("Leader");
oldLeader.tag = "Friendly";
}

gameObject.tag = "Leader";

}
}
}
}

void Update () {
foreach (GameObject Friendly in friendlies) {
if (this.Friendly.tag != "Leader") {
GameObject Leader = (GameObject.FindWithTag("Leader"));
float speed = 1 * Time.deltaTime;
target = Leader.transform;
transform.position = Vector3.MoveTowards(transform.position, target.position, speed);
}
}
}
}

This file was deleted.

Binary file not shown.
Binary file not shown.