public static DInput bulletsUpAhead(ResourceFightDNCreature p_cre) { DActivationFunction activate = ActivationFactory.generateSigmoid(5, 1, false, true, false); return(() => { GameObject[] bullets = p_cre.sense("BULLET"); // Debug.Log(bullets.Length + " : " + activate(bullets.Length)); return activate(bullets.Length); }); }
//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; }); }