private void SplitMuscle(OrganismSetup organism) { if (organism.muscles.Count == 0) { return; } MuscleSetup muscleA = organism.muscles.OrderBy(v => Random.value).FirstOrDefault(); float lerp = Random.Range(0.4f, 0.6f); //Where the slice will happen on the muscle MuscleSetup muscleB = muscle.Randomize(muscleA); muscleA.relaxedDistance *= lerp; muscleB.relaxedDistance *= (1 - lerp); JointSetup newJoint = joint.Randomize( organism.joints[muscleA.jointA].Lerp(organism.joints[muscleA.jointB], lerp) ); int jointPos = organism.joints.Count; muscleA.jointB = jointPos; muscleB.jointA = jointPos; organism.joints.Add(newJoint); organism.muscles.Add(muscleB); }
public void Spawn(Vector3 pos) { Rect boundaries = new Rect(0, 0, 0, 0); for (int i = 0; i < setup.joints.Count; i++) { JointSetup s = setup.joints[i]; if (s == null) { continue; } OrganismJoint joint = OrganismManager.JointPool.Take(); joint.transform.SetParent(transform); s.Apply(joint); joints.Add(joint); Rect jointBounds = new Rect(s.position - Vector2.one * joint.Radius, new Vector2(joint.Radius * 2, joint.Radius * 2)); if (i == 0 || jointBounds.xMin < boundaries.xMin) { boundaries.xMin = jointBounds.xMin; } if (i == 0 || jointBounds.xMax > boundaries.xMax) { boundaries.xMax = jointBounds.xMax; } if (i == 0 || jointBounds.yMin < boundaries.yMin) { boundaries.yMin = jointBounds.yMin; boundaries.yMax = jointBounds.yMax; } } for (int i = 0; i < setup.muscles.Count; i++) { MuscleSetup s = setup.muscles[i]; if (setup.joints [s.jointA] == null || setup.joints [s.jointB] == null) { continue; } OrganismMuscle muscle = OrganismManager.MusclePool.Take(); muscle.jointA = joints[s.jointA]; muscle.jointB = joints[s.jointB]; muscle.transform.SetParent(transform); s.Apply(muscle); muscles.Add(muscle); } transform.position = pos + new Vector3(boundaries.center.x, -boundaries.yMin + 0.01f); gameObject.SetActive(true); }
public JointSetup Lerp(JointSetup to, float lerp) { return(new JointSetup() { position = Vector2.Lerp(position, to.position, lerp), size = Mathf.Lerp(size, to.size, lerp), weight = Mathf.Lerp(weight, to.weight, lerp), friction = Mathf.Lerp(friction, to.friction, lerp), bounciness = Mathf.Lerp(bounciness, to.bounciness, lerp) }); }
public void CreateJoint(OrganismSetup organism) { int jointA = Random.Range(0, organism.joints.Count); //To which joint the new joint will be attached? int jointB = organism.joints.Count; //The new joint ID; JointSetup newJoint = joint.Randomize(organism.joints[jointA]); MuscleSetup newMuscle = muscle.FullRandomize(); newMuscle.jointA = jointA; newMuscle.jointB = jointB; organism.joints.Add(newJoint); organism.muscles.Add(newMuscle); }