void Start() { var creaturesSpecs = new List <CreatureSpec>(); var cl = new CreatureLimitSpec((2, 5), (0.1f, 2), (-100, 100), (0, 1000), 3); var template = new CreatureSpec(cl); var m = new MutationSpec( chanceOfLengthChange: 0.1f, chanceOfLimbCountChange: 0.1f, chanceOfMotorSpeedChange: 0.1f, chanceOfMotorTourqueChange: 0.1f, minMaxLengthChange: (-1, 1), minMaxLimbCountChange: (-2, 2), minMaxMotorSpeedChange: (-100, 100), minMaxMotorTourqueChange: (-1000, 1000), //TODO use for this the CreatureLimitSpec minMaxLength: (0.1f, 2), minMaxLimbCount: (1, 10), minMaxMotorSpeed: (-100, 100), minMaxMotorTourque: (0, 1000) ); for (int i = 0; i < 10; i++) { CreatureSpec spec = template; for (int j = 0; j < 100; j++) { spec = (m.Mutate(spec)); } CreateCreatureFromSpec(spec); creaturesSpecs.Add(spec); } }
void CreateCreatureFromSpec(CreatureSpec creatureSpec) { var creatureParent = new GameObject($"Creature_{newestCreatureId++}", typeof(Creature)).GetComponent <Creature>(); creatureParent.creatureSpec = creatureSpec; for (int i = 0; i < creatureSpec.structSpec.Count; i++) { var a = creatureSpec.structSpec[i].Item1; var b = creatureSpec.structSpec[i].Item2; var aGo = creatureParent.GetOrCreateJoint(a); var bGo = creatureParent.GetOrCreateJoint(b); print(i); print(creatureSpec.nodeDistances.Count); print(creatureSpec.structSpec.Count); print(""); var connectionDistance = creatureSpec.nodeDistances[i]; var joint = aGo.AddComponent <HingeJoint2D>(); joint.autoConfigureConnectedAnchor = false; joint.connectedAnchor = new Vector2(connectionDistance, 0); joint.motor = creatureSpec.motorSpec[i]; joint.useMotor = true; joint.connectedBody = bGo.GetComponent <Rigidbody2D>(); var body = Instantiate(Prefabs.instance.bodyPrefab, bGo.transform.position, bGo.transform.rotation); body.transform.SetParent(bGo.transform); body.transform.localScale = new Vector3(connectionDistance, body.transform.localScale.y, body.transform.localScale.z); body.transform.localPosition = new Vector3(connectionDistance / 2, body.transform.localPosition.y, body.transform.localPosition.z); } }