//expected to be a turn update public void CastFireUpdate() { //model.transform.forward = direction; self.transform.forward = direction; //todo produce a fireball unitbehavior that moves to TargetLocator's position after say 40 frames //Debug.Log("procced =: " + HasProcced); if (!HasProcced) { if (CurrentTime - StartTime > ProcTime) { //CAST FIRE BALL //start firestrike animation List <UnitBehavior> EligibleUnits = new List <UnitBehavior>(), pulled = GetSusceptibleUnits(); //Debug.Log("GetSusceptibleUnits gave " + pulled.Count + " units."); foreach (UnitBehavior unit in pulled) { //determine distance/angle Vector3 diff = unit.transform.position - origin; // short if distance is too great. if (diff.magnitude - unit.GetComponent <CapsuleCollider>().radius > direction.magnitude) { continue; } float L = self.transform.GetComponent <SphereCollider>().radius; float H = L * 2; Ray r = new Ray(origin, direction.normalized); float o = Vector3.Cross(r.direction, diff).magnitude; // skip this unit if outside hitbox influence; if (o - unit.GetComponent <CapsuleCollider>().radius > L + (H - L) * (diff.magnitude / direction.magnitude)) { continue; } //add the eligible enemies to the list. EligibleUnits.Add(unit); } if (EligibleUnits.Count < 1) { Debug.Log("no units hit."); HasProcced = true; return; } //hit the closest enemy code below /* * UnitBehavior hit = EligibleUnits[0]; * foreach(UnitBehavior unit in EligibleUnits) * { * if ((unit.transform.position - origin).magnitude < (hit.transform.position - origin).magnitude) * { * hit = unit; * } * } * hit.DamageHealth(self.GetSkill(actiontype)); */ //hit all enemies able to be hit code below foreach (UnitBehavior unit in EligibleUnits) { unit.DamageHealth(self.GetSkill(actiontype)); } HasProcced = true; } } CurrentTime = Time.time; }