private GameObject[] sense(string p_type) { GameObject[] all_of_type = ObjectLogger.getByType(p_type); List <GameObject> in_arc = new List <GameObject>(); foreach (GameObject ob in all_of_type) { if (ob == null) { continue; } Vector3 diff = ob.transform.position - gameObject.transform.position; if (Vector2Calc.checkAngle(diff, m_forward, m_sense_angle) && diff.magnitude <= m_sense_proximity) { in_arc.Add(ob); } } // foreach(GameObject ob in in_arc){ // Debug.DrawLine(gameObject.transform.position, ob.transform.position, Color.cyan, 1f); // } return(in_arc.ToArray()); }
//Dodging public static DInput bulletCollisionImminent(ResourceFightDNCreature p_cre) { DActivationFunction prox_activate = ActivationFactory.generateSigmoid(1.5f, 2, false, true, true); DActivationFunction angle_activate = ActivationFactory.generateSigmoid(10f, 2, false, true, true); DActivationFunction full_activate = ActivationFactory.generateSigmoid(1, 1, false, true, false); return(() => { GameObject[] bullets = p_cre.sense("BULLET"); List <GameObject> bullets_close_and_coming_towards = new List <GameObject>(); foreach (GameObject bul in bullets) { if (Vector2Calc.proximity(bul.transform.position, p_cre.transform.position) < 2 && Vector2Calc.checkAngle(p_cre.transform.position - bul.transform.position, bul.GetComponent <Rigidbody2D>().velocity, 10)) { bullets_close_and_coming_towards.Add(bul); } } float activation = 0; foreach (GameObject bul in bullets_close_and_coming_towards) { float bul_prox = prox_activate(Vector2Calc.proximity(bul.transform.position, p_cre.transform.position) - 0.5f); float bul_angle = angle_activate(Mathf.Abs(Vector2Calc.getAngle(p_cre.transform.position - bul.transform.position, bul.GetComponent <Rigidbody2D>().velocity))); float bul_active = full_activate(bul_prox * bul_angle); if (bul_active > activation) { activation = bul_active; } } //if(activation >0 ) Debug.Log(activation); return activation; }); }