public static DOutput aim_at_nearest_creature(ResourceFightDNCreature p_cre) { return((float p_input) => { GameObject creature = p_cre.senseClosest("CREATURE"); if (creature) { float angle = Vector2Calc.getAngle(p_cre.m_forward, creature.transform.position - p_cre.transform.position); p_cre.m_actions.add("ROTATE", p_input, () => { p_cre.transform.Rotate(0, 0, -2 * Mathf.Sign(angle)); }); } else { return; } }); }
public static DOutput search_resource(ResourceFightDNCreature p_cre) { return((float p_input) => { GameObject resource = p_cre.senseClosest("RESOURCE"); if (resource) { float angle = Vector2Calc.getAngle(p_cre.m_forward, resource.transform.position - p_cre.transform.position); p_cre.m_actions.add("ROTATE", p_input, () => { p_cre.transform.Rotate(0, 0, -2 * Mathf.Sign(angle)); }); if (angle < 10f) { p_cre.m_actions.add("MOVE", p_input, () => { p_cre.move(p_cre.m_forward); }); } } else { p_cre.m_actions.add("ROTATE", p_input, () => { p_cre.transform.Rotate(0, 0, 1); }); } }); }
//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; }); }