//expected to be a turn update public void BasicAttackUpdate() { Turn X = MyUnit.GetCombatActionQueue()[0]; //model.transform.forward = direction; X.direction = (player.transform.position - MyUnit.transform.position).normalized * 1.5f; MyUnit.transform.forward = X.direction; //todo produce a fireball unitbehavior that moves to TargetLocator's position after say 40 frames //Debug.Log("procced =: " + X.HasProcced); if (!X.HasProcced) { //test to see if we dont hit the player. if (X.CurrentTime - X.StartTime > X.ProcTime) { bool hit = true; //determine distance/angle Vector3 diff = player.transform.position - MyUnit.transform.position; // short if distance is too great. if (diff.magnitude > 1.5f) { X.HasProcced = true; hit = false; } else { float L = MyUnit.transform.GetComponent <CapsuleCollider>().radius; float H = L * 2; Ray r = new Ray(MyUnit.transform.position, X.direction.normalized); float o = Vector3.Cross(r.direction, diff).magnitude; // Hit this unit if inside hitbox influence; if ((o - player.GetComponent <SphereCollider>().radius) > L + (H - L) * (diff.magnitude / X.ran)) { hit = false; } Debug.Log("Hit is: " + hit); } X.HasProcced = true; if (hit) { player.DamageHealth(MyUnit.GetSkill("basicattack")); } } } }
//expected to be a turn update public void BasicAttackUpdate() { //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 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 > ran) { 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 / ran)) { 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; } } }