static LocoStep Mutate(LocoStep source) { //Spawn a new mutant var mutant = SpawnNew(source.Joint); //Inherit from src properties mutant.At += Gaussian.RandomHalfHalf() * LocoStep.GaitDuration; while (mutant.At >= LocoStep.GaitDuration) { mutant.At -= LocoStep.GaitDuration; } while (mutant.At < 0) { mutant.At += LocoStep.GaitDuration; } mutant.Force += Gaussian.RandomHalfHalf() * MaxForce; mutant.Force = Mathf.Clamp(mutant.Force, 0, MaxForce); mutant.Duration += Gaussian.RandomHalfHalf() * LocoStep.GaitDuration; mutant.Duration = Mathf.Clamp(mutant.Duration, 0, MaxForce); mutant.Rotation += new Vector3(Gaussian.RandomHalfHalf(), Gaussian.RandomHalfHalf(), Gaussian.RandomHalfHalf()); mutant.Duration = Mathf.Clamp(mutant.Duration, 0, MaxForce); return(mutant); }
public Locomotion(int index, Locomotion parent) : base() { Index = index; if (parent != null) { Color = LocoStep.Mutate(parent.Color); } else { Color = new Color(UnityEngine.Random.Range(0f, 1f), UnityEngine.Random.Range(0f, 1f), UnityEngine.Random.Range(0f, 1f)); } const int MonsPerRow = 10; var pos = new Vector3((index % MonsPerRow) * 3f, -1.38f, Mathf.Floor(index / MonsPerRow) * 6f); var physicsLayer = 8 + (index % 20); _monster = new Monster(physicsLayer, Color); _monster.Transform.position = pos; if (parent != null) { Steps = LocoStep.Mutate(parent.Steps); } else { Steps = new List <LocoStep>(); foreach (var joint in _monster.Joints.Keys) { var temp = joint; Steps.Add(LocoStep.SpawnNew(temp)); Steps.Add(LocoStep.SpawnNew(temp)); } } for (var i = 0; i < Steps.Count; ++i) { Steps[i].NextAt = Steps[i].At; } _monster.UnityFixedUpdate += OnFixedUpdate; }
static LocoStep Mutate(LocoStep source) { //Spawn a new mutant var mutant = SpawnNew(source.Joint); //Inherit from src properties mutant.At += Gaussian.RandomHalfHalf() * LocoStep.GaitDuration; while (mutant.At >= LocoStep.GaitDuration) mutant.At -= LocoStep.GaitDuration; while (mutant.At < 0) mutant.At += LocoStep.GaitDuration; mutant.Force += Gaussian.RandomHalfHalf() * MaxForce; mutant.Force = Mathf.Clamp(mutant.Force, 0, MaxForce); mutant.Duration += Gaussian.RandomHalfHalf() * LocoStep.GaitDuration; mutant.Duration = Mathf.Clamp(mutant.Duration, 0, MaxForce); mutant.Rotation += new Vector3(Gaussian.RandomHalfHalf(), Gaussian.RandomHalfHalf(), Gaussian.RandomHalfHalf()); mutant.Duration = Mathf.Clamp(mutant.Duration, 0, MaxForce); return mutant; }