Пример #1
0
    // Creating skidmarks.
    void SkidMarks()
    {
        // First, we are getting groundhit data.
        WheelHit GroundHit;

        wheelCollider.GetGroundHit(out GroundHit);

        // Forward, sideways, and total slips.
        wheelSlipAmountSideways = Mathf.Abs(GroundHit.sidewaysSlip);
        wheelSlipAmountForward  = Mathf.Abs(GroundHit.forwardSlip);
        totalSlip = wheelSlipAmountSideways + (wheelSlipAmountForward / 2f);

        // If scene has skidmarks manager...
        if (skidmarks)
        {
            // If slips are bigger than target value...
            if (wheelSlipAmountSideways > startSlipValue || wheelSlipAmountForward > startSlipValue * 2f)
            {
                Vector3 skidPoint = GroundHit.point + 2f * (rigid.velocity) * Time.deltaTime;

                if (rigid.velocity.magnitude > 1f)
                {
                    lastSkidmark = skidmarks.AddSkidMark(skidPoint, GroundHit.normal, (wheelSlipAmountSideways / 2f) + (wheelSlipAmountForward / 2f), lastSkidmark);
                }
                else
                {
                    lastSkidmark = -1;
                }
            }
            else
            {
                lastSkidmark = -1;
            }
        }
    }
Пример #2
0
    void SkidMarks()
    {
        WheelHit GroundHit;

        wheelCollider.GetGroundHit(out GroundHit);

        wheelSlipAmountSideways = Mathf.Abs(GroundHit.sidewaysSlip);
        wheelSlipAmountForward  = Mathf.Abs(GroundHit.forwardSlip);
        totalSlip = wheelSlipAmountSideways + (wheelSlipAmountForward / 2f);

        if (skidmarks)
        {
            if (wheelSlipAmountSideways > startSlipValue || wheelSlipAmountForward > startSlipValue * 2f)
            {
                Vector3 skidPoint = GroundHit.point + 2f * (rigid.velocity) * Time.deltaTime;

                if (rigid.velocity.magnitude > 1f)
                {
                    lastSkidmark      = skidmarks.AddSkidMark(skidPoint, GroundHit.normal, (wheelSlipAmountSideways / 2f) + (wheelSlipAmountForward / 2f), lastSkidmark);
                    wheelTemparature += ((wheelSlipAmountSideways / 2f) + (wheelSlipAmountForward / 2f)) / ((Time.fixedDeltaTime * 100f) * Mathf.Lerp(1f, 5f, wheelTemparature / 150f));
                }
                else
                {
                    lastSkidmark      = -1;
                    wheelTemparature -= Time.fixedDeltaTime * 5f;
                }
            }
            else
            {
                lastSkidmark      = -1;
                wheelTemparature -= Time.fixedDeltaTime * 5f;
            }

            wheelTemparature = Mathf.Clamp(wheelTemparature, 0f, 150f);
        }
    }