// Component methods


    void OnEnable()
    {
        m_rigidbody = GetComponent <Rigidbody>();

        m_inertiaHelper.settings = inertia;
        m_inertiaHelper.Apply(m_rigidbody);
        m_lastAngularVelocity = m_rigidbody.angularVelocity;
        m_lastEulerAngles     = m_rigidbody.rotation.eulerAngles;
        m_lastEulerVelocity   = Vector3.zero;
        m_minEulerAngles      = m_lastEulerAngles;
        m_maxEulerAngles      = m_lastEulerAngles;

        Time.timeScale      = timeScale;
        Time.fixedDeltaTime = deltaTime;
        m_internalTime      = 0.0f;
        m_internalFrame     = 0;

        m_text    = "";
        m_results = "";
    }
Exemplo n.º 2
0
    protected override void OnInitialize()
    {
        // Prepare the internal helpers: inertia, steering

        m_inertia          = new Inertia();
        m_inertia.settings = inertia;
        m_inertia.Apply(cachedRigidbody);

        m_steering          = new Steering();
        m_steering.settings = steering;

        // Declare the number of wheels

        SetNumberOfWheels(4);

        // Verify wheel references

        if (frontAxle.leftWheel == null || frontAxle.rightWheel == null ||
            rearAxle.leftWheel == null || rearAxle.rightWheel == null)
        {
            DebugLogError("Some VPWheelCollider references are missing in the axles.\nAll axles must have a reference to the corresponding left-right VPWheelCollider objects.");
            enabled = false;
            return;
        }

        // Initialize tire friction

        if (frontTires == null || rearTires == null)
        {
            DebugLogError("Missing tire settings. Ensure both front and rear tires are set");
            enabled = false;
            return;
        }

        // We now have the inherited properties wheels[wheelCount] and wheelsState[wheelCount].
        // Configure the wheels in the axles accordingly:
        //
        //	- Mandatory data
        //	- Steering
        //	- Brakes

        ConfigureAxle(frontAxle, 0, 1, frontTires.GetTireFriction());
        ConfigureAxle(rearAxle, 2, 3, rearTires.GetTireFriction());

        // Configure an independent powertrain per axle

        m_frontPowertrain = new Powertrain(wheels[0], wheels[1]);
        m_frontPowertrain.mgu.settings          = frontMgu;
        m_frontPowertrain.differential.settings = frontDifferential;

        m_rearPowertrain = new Powertrain(wheels[2], wheels[3]);
        m_rearPowertrain.mgu.settings          = rearMgu;
        m_rearPowertrain.differential.settings = rearDifferential;

        // Configure axle sensors

        m_frontAxleSensor.Configure(this, 0);
        m_rearAxleSensor.Configure(this, 1);

        // Initialize internal data

        m_gearMode     = (int)Gearbox.AutomaticGear.N;
        m_prevGearMode = (int)Gearbox.AutomaticGear.N;
        data.Set(Channel.Input, InputData.AutomaticGear, m_gearMode);
    }