public void ActivateJoint(JointSegment parent, SideType side) { var joint = CreateJoint(); joint.connectedBody = parent.Body; joint.axis = Helper.directions[Helper.Axis(side)]; joint.swingAxis = Helper.directions[Helper.SwingAxis(side)]; joint.anchor = Helper.directions[Helper.Inverse(side)] * 0.5f; }
public JointSampleCreature(JointSegment body, DNA dna) { this.target = body.transform.position + body.transform.forward * distance; GetAllSegments(body); this.body = body; this.dna = dna; network = new Network(GetLayersCount(), this.dna.genes); }
public JointSampleCreature(JointSegment body) { this.target = body.transform.position + body.transform.forward * distance; GetAllSegments(body); this.body = body; this.dna = new DNA(GetGenesCount(), new Vector2(-1f, 1f)); network = new Network(GetLayersCount()); }
void GetAllSegments(JointSegment root) { sensors.Add(new TransformAngleSensor(root.transform)); sensors.Add(new PartContactsSensor(root)); sensors.Add(new DirectionSensor(root.transform, target)); effectors.Add(root); root.Segments.ForEach(child => { GetAllSegments(child); }); }
void Build(Transform group, JointSegment parentSegment, SideType side, Node childNode) { var cur = Instantiate(segmentPrefab).GetComponent <JointSegment>(); cur.transform.parent = group; cur.transform.localScale = childNode.Size; cur.Connect(parentSegment, side); var cons = childNode.GetConnections(); for (int i = 0, n = cons.Length; i < n; i++) { var con = cons[i]; Build(group, cur, con.Side, con.To); } }
public void Init(JointSegment parent) { Body.velocity *= 0f; Body.angularVelocity *= 0f; Body.mass = transform.localScale.magnitude; // transform.position = parent.transform.position + Helper.directions[side] * 1.25f; var dir = Helper.directions[side]; var po = Vector3.Scale(dir, parent.transform.localScale) * 0.5f; var lo = Vector3.Scale(dir, transform.localScale) * 0.5f; var offset = po + lo + lo * 0.25f; transform.position = parent.transform.position + offset; // need to add HingeJoint after setting position if (this.joint == null) { ActivateJoint(parent, side); } Init(); }
public void AddSegment(JointSegment segment) { segments.Add(segment); }
public void Connect(JointSegment parent, SideType side) { this.side = side; Init(parent); parent.AddSegment(this); }