Пример #1
0
        public void SetChromosome(CarChromosome chromosome, CarSampleConfig config)
        {
            Chromosome                 = chromosome;
            Chromosome.MaxDistance     = 0;
            chromosome.MaxDistanceTime = 0;
            Distance           = 0;
            DistanceTime       = 0;
            m_startTime        = Time.time;
            transform.rotation = Quaternion.identity;

            m_config             = config;
            m_rb.isKinematic     = false;
            m_rb.velocity        = Vector2.zero;
            m_rb.angularVelocity = 0;

            var phenotypes = chromosome.GetPhenotypes();

            m_polygon.points = phenotypes.Select(p => p.Vector).ToArray();
            var wheelsMass = 0f;

            for (int i = 0; i < phenotypes.Length; i++)
            {
                var p = phenotypes[i];
                PrepareWheel(i, m_polygon.points[p.WheelIndex], p.WheelRadius);
                wheelsMass += p.WheelRadius;
            }

            // The car mass should be greater than wheels sum mass, because the WheelJoint2d get crazy otherwise.
            // If we comment the line bellow and enable the car mass should be greater than wheels sum mass, because the WheelJoint2d get crazy otherwise.
            m_rb.mass = 1 + m_polygon.points.Sum(p => p.magnitude) * VectorMagnitudeMass + wheelsMass;

            if (m_cam != null)
            {
                m_cam.StartFollowing(gameObject);
            }

            StartCoroutine("CheckTimeout");
        }