Exemple #1
0
 private void getSurface()
 {
     for (int i = 0; i < wheelStructs.Count; i++)
     {
         PhysXWheelHit hit = PhysXWheelHit.GetWheelHit();
         if (wheelStructs[i].collider.GetGroundHit(hit))   //for each wheel
         // if new ground type, set new stiffness
         {
             if (hit.collider.CompareTag("DustGround") && wheelStructs[i].surface != "DustGround")
             {
                 wheelStructs[i] = new wheelStruct(5f, "DustGround", wheelStructs[i].collider);
             }
             else if (hit.collider.CompareTag("RoadGround") && wheelStructs[i].surface != "RoadGround")
             {
                 wheelStructs[i] = new wheelStruct(5f, "RoadGround", wheelStructs[i].collider);
             }
             else if (hit.collider.CompareTag("CaveGround") && wheelStructs[i].surface != "CaveGround")
             {
                 wheelStructs[i] = new wheelStruct(5f, "CaveGround", wheelStructs[i].collider);
             }
             else
             {
                 wheelStructs[i] = new wheelStruct(8f, "0", wheelStructs[i].collider);
             }
         }
         PhysXWheelHit.ReleaseWheelHit(hit);
     }
 }
Exemple #2
0
    private void AntiRoll(PhysXWheelCollider left, PhysXWheelCollider right)
    {
        //anti-roll bar simulations. Keeps the vehicle stable

        PhysXWheelHit lHit      = PhysXWheelHit.GetWheelHit();
        PhysXWheelHit rHit      = PhysXWheelHit.GetWheelHit();
        bool          lGrounded = left.GetGroundHit(lHit);
        bool          rGrounded = right.GetGroundHit(rHit);
        float         lDistance = 1f;
        float         rDistance = 1f;

        if (lGrounded)
        {
            lDistance = (-left.transform.InverseTransformPoint(lHit.point).y - left.radius) / left.suspensionDistance;
        }

        if (rGrounded)
        {
            rDistance = (-right.transform.InverseTransformPoint(rHit.point).y - right.radius) / right.suspensionDistance;
        }

        float addedForce = (lDistance - rDistance) * antiRollStiffness;

        if (lGrounded)
        {
            carRB.AddForceAtPosition(left.transform.up * -addedForce, left.transform.position, ForceMode.Force);
        }

        if (rGrounded)
        {
            carRB.AddForceAtPosition(right.transform.up * addedForce, right.transform.position, ForceMode.Force);
        }
        PhysXWheelHit.ReleaseWheelHit(lHit);
        PhysXWheelHit.ReleaseWheelHit(rHit);
    }
Exemple #3
0
    private void Particles()
    {
        PhysXWheelHit lHit           = PhysXWheelHit.GetWheelHit();
        PhysXWheelHit rHit           = PhysXWheelHit.GetWheelHit();
        bool          lGrounded      = rearLeftW.GetGroundHit(lHit);
        bool          rGrounded      = rearRightW.GetGroundHit(rHit);
        var           lDustEmmissiom = leftDust.emission;
        var           rDustEmmissiom = rightDust.emission;
        var           lCaveEmmissiom = leftGravel.emission;
        var           rCaveEmmissiom = rightGravel.emission;

        // left rear dust emission
        if (lGrounded && (Mathf.Abs(rearLeftW.rpm) > 150 || carRB.velocity.magnitude > 5))
        {
            if (lHit.collider.CompareTag("DustGround"))
            {
                lDustEmmissiom.enabled = true;
                lCaveEmmissiom.enabled = false;
            }
            else if (lHit.collider.CompareTag("CaveGround"))
            {
                lDustEmmissiom.enabled = false;
                lCaveEmmissiom.enabled = true;
            }
            else
            {
                lDustEmmissiom.enabled = false;
                lCaveEmmissiom.enabled = false;
            }
        }
        else
        {
            lDustEmmissiom.enabled = false;
            lCaveEmmissiom.enabled = false;
        }

        // right rear dust emission
        if (rGrounded && (Mathf.Abs(rearRightW.rpm) > 150 || carRB.velocity.magnitude > 5))
        {
            if (rHit.collider.CompareTag("DustGround"))
            {
                rDustEmmissiom.enabled = true;
                rCaveEmmissiom.enabled = false;
            }
            else if (rHit.collider.CompareTag("CaveGround"))
            {
                rDustEmmissiom.enabled = false;
                rCaveEmmissiom.enabled = true;
            }
            else
            {
                rDustEmmissiom.enabled = false;
                rCaveEmmissiom.enabled = false;
            }
        }
        else
        {
            rDustEmmissiom.enabled = false;
            rCaveEmmissiom.enabled = false;
        }

        PhysXWheelHit.ReleaseWheelHit(lHit);
        PhysXWheelHit.ReleaseWheelHit(rHit);
    }