コード例 #1
0
        // Initialize the controller and blocks

        protected override void OnInitialize()
        {
            // Declare the number of wheels

            SetNumberOfWheels(4);

            if (wheelFL == null || wheelFR == null || wheelRL == null || wheelRR == null)
            {
                Debug.LogError("Missing VPWheelCollider");
                return;
            }

            // Configure mandatory data per wheel

            ConfigureWheelData(wheelState[0], wheels[0], wheelFL, true);
            ConfigureWheelData(wheelState[1], wheels[1], wheelFR, true);
            ConfigureWheelData(wheelState[2], wheels[2], wheelRL);
            ConfigureWheelData(wheelState[3], wheels[3], wheelRR);

            // Initialize DirectDrive and connect it to the rear wheels via differential

            m_directDrive  = new DirectDrive();
            m_differential = new Differential();
            m_differential.settings.gearRatio = 1.0f;

            Block.Connect(wheels[2], 0, m_differential, 0);
            Block.Connect(wheels[3], 0, m_differential, 1);
            Block.Connect(m_differential, 0, m_directDrive, 0);
        }
コード例 #2
0
        // Convert the input state into torque and brake in the track

        void SendInputToTrack(int input, DirectDrive track, Wheel w0, Wheel w1, Wheel w2, Wheel w3)
        {
            track.maxMotorTorque = trackTorque;
            track.maxRpm         = trackRpm;

            if (input == 0)
            {
                float brakeTorque = trackBrakeTorque * 0.25f;           // 4 wheels per track

                w0.AddBrakeTorque(brakeTorque);
                w1.AddBrakeTorque(brakeTorque);
                w2.AddBrakeTorque(brakeTorque);
                w3.AddBrakeTorque(brakeTorque);
                track.motorInput = 0.0f;
            }
            else
            {
                track.motorInput = Mathf.Sign(input);
            }
        }
コード例 #3
0
        // Initialize the controller and blocks

        protected override void OnInitialize()
        {
            // Declare the number of wheels

            SetNumberOfWheels(8);

            if (LeftTrack0 == null || LeftTrack1 == null || LeftTrack2 == null || LeftTrack3 == null ||
                RightTrack0 == null || RightTrack1 == null || RightTrack2 == null || RightTrack3 == null)
            {
                Debug.LogError("Missing VPWheelCollider");
                return;
            }

            // Configure mandatory data per wheel

            ConfigureWheelData(wheelState[0], wheels[0], LeftTrack0);
            ConfigureWheelData(wheelState[1], wheels[1], LeftTrack1);
            ConfigureWheelData(wheelState[2], wheels[2], LeftTrack2);
            ConfigureWheelData(wheelState[3], wheels[3], LeftTrack3);

            ConfigureWheelData(wheelState[4], wheels[4], RightTrack0);
            ConfigureWheelData(wheelState[5], wheels[5], RightTrack1);
            ConfigureWheelData(wheelState[6], wheels[6], RightTrack2);
            ConfigureWheelData(wheelState[7], wheels[7], RightTrack3);

            // Initialize DirectDrive blocks and conect each one with its track

            m_leftDrive  = new DirectDrive();
            m_rightDrive = new DirectDrive();

            SetupTrackTransmission(m_leftDrive, wheels[0], wheels[1], wheels[2], wheels[3]);
            SetupTrackTransmission(m_rightDrive, wheels[4], wheels[5], wheels[6], wheels[7]);

            // Set up the relaxed criteria for putting the wheels to sleep. This allows half of the
            // wheels to be braked without the vehicle entering in full sleep mode.

            vehicleSleepCriteria = VehicleSleepCriteria.Relaxed;
        }