Ejemplo n.º 1
0
        public override void CollectObservations(VectorSensor sensor)
        {
            Vector3 pos = transform.position;

            m_Road.Find(pos, out m_RoadPosition, out m_RoadForward);
            Vector3 delta = pos - m_RoadPosition;

            float anglePos = Vector3.SignedAngle(m_RoadForward, delta, Vector3.up);

            sensor.AddObservation(Mathf.Clamp(anglePos / 90f, -1f, 1f));
            sensor.AddObservation(Sigmoid(delta.sqrMagnitude) * Mathf.Sign(anglePos));

            float angleFwd = Vector3.SignedAngle(m_RoadForward, transform.forward, Vector3.up);

            sensor.AddObservation(angleFwd / 180f);

            Vector3 localVelocity = m_Physics.Localize(m_Physics.Velocity);

            sensor.AddObservation(Sigmoid(localVelocity.x));
            sensor.AddObservation(Sigmoid(localVelocity.y));
            // Forward speed 0 - 50.
            // http://fooplot.com/#W3sidHlwZSI6MCwiZXEiOiIoeCowLjEpLygxK2FicygoeCowLjEpKSkqMi40LTEiLCJjb2xvciI6IiMwMDAwMDAifSx7InR5cGUiOjEwMDAsIndpbmRvdyI6WyItMjAuODc5NjU3NDUxOTIzMDciLCI3MC42NzMwNzY5MjMwNzY4OCIsIi0zLjg0NDI5OTMxNjQwNjI0NzMiLCI1LjMxMDk3NDEyMTA5Mzc0NjQiXX1d
            sensor.AddObservation(Mathf.Clamp(
                                      Sigmoid(localVelocity.z, 0.1f) * 2.4f - 1f, -1f, 1f));

            sensor.AddObservation(m_Physics.Inclination);
            sensor.AddObservation(m_Physics.WheelF.NormSteer);
            sensor.AddObservation(m_Physics.WheelR.NormMotorTorque);
            sensor.AddObservation(m_Physics.WheelF.NormBrakeTorque);
            sensor.AddObservation(m_Physics.WheelR.NormBrakeTorque);
            sensor.AddObservation(m_Physics.WheelF.IsGrounded);
            sensor.AddObservation(m_Physics.WheelR.IsGrounded);
            sensor.AddObservation(m_Physics.WheelF.GetHeightAboveGround());
            sensor.AddObservation(m_Physics.WheelR.GetHeightAboveGround());
        }
Ejemplo n.º 2
0
        private void Update()
        {
            float t = physics.WheelF.NormSteer;

            foreach (var pose in laraAnim)
            {
                pose.Blend(t);
            }

            float speed = Mathf.Min(physics.Velocity.magnitude / 25f, 1f);
            float drive = (speed + 0.5f) * (physics.WheelR.RPMRatio + 0.5f) * 0.5f;
            float jump  = Mathf.Min(Mathf.Sqrt(Mathf.Abs(physics.Velocity.y)), 1f);
            float turn  = Mathf.Abs(physics.Localize(physics.AngularVelocity).y / 2.5f);
            float slip  = physics.WheelR.sLong * physics.WheelF.sLong;
            float fric  = Mathf.Max(turn, slip < 1f ? slip : 0f);
            float brake = physics.WheelR.BrakeRatio + physics.WheelF.BrakeRatio;

            var emission = particles.emission;

            emission.rateOverDistance = fric * smokeDensity;

            motor1.volume = 0.65f - drive * 0.4f;
            motor1.pitch  = 1f + drive;

            motor2.volume = drive;
            motor2.pitch  = 0.7f + drive * 0.3f;

            tires1.volume = fric * 0.75f;
            tires2.volume = brake * speed * 2f;

            if (groundedR != physics.WheelR.IsGrounded)
            {
                groundedR = physics.WheelR.IsGrounded;
                if (groundedR)
                {
                    thud1.PlayOneShot(thud1.clip, jump);
                }
            }
            if (groundedF != physics.WheelF.IsGrounded)
            {
                groundedF = physics.WheelF.IsGrounded;
                if (groundedF)
                {
                    thud2.PlayOneShot(thud2.clip, jump);
                }
            }
        }