Example #1
0
    // Start is called before the first frame update
    void Start()
    {
        if (customPacejka == null)
        {
            Debug.LogWarning("You need to assign a Pacejka. Using a default one");

            GameObject pacObj = new GameObject("Pacejka");
            pacObj.AddComponent <CWPacejka>();
            customPacejka = pacObj.GetComponent <CWPacejka>();
        }

        if (carRigidbody == null)
        {
            Debug.LogWarning("No Rigidbody was assigned. Chose one in parent");

            carRigidbody = GetComponentInParent <Rigidbody>();
            if (carRigidbody == null)
            {
                Debug.LogError("No Rigidbody was found. You need a rigidbody in one of the parent objects");
            }
        }

        if (wheelMesh == null)
        {
            //Debug.LogWarning("No wheel mesh was found");
        }


        cwWheel             = new CWWheel(this, transform, carRigidbody, customPacejka, wheelMesh, restLength, springTravel, springStiffness, springDamping, wheelRadius, wheelMass);
        cwWheelTorqueDistr  = new CWWheelTorqueDistr(this, cwWheel, carRigidbody, customPacejka, hasMotor);
        cwWheel.torqueDistr = cwWheelTorqueDistr;

        cwWheel.debugMessages = debugMessages;
    }
Example #2
0
    public CWWheelTorqueDistr(WheelColliderAdv _wheelColliderAdv, CWWheel _wheel, Rigidbody rigidbody, CWPacejka cWPacejka, bool _hasMotor)
    {
        wheelColliderAdv = _wheelColliderAdv;
        wheel            = _wheel;
        rb       = rigidbody;
        pacejka  = cWPacejka;
        hasMotor = _hasMotor;

        //Start
        wheelMass   = wheel.WheelMass;
        wheelRadius = wheel.Radius;
        J           = wheelMass * wheelRadius * wheelRadius * 0.5f;

        slowdownFac       *= (wheelMass / 15f);
        slowdownFacDamper *= (wheelMass / 15f);
    }
Example #3
0
    public CWWheel(WheelColliderAdv _wheelColliderAdv, Transform _transform, Rigidbody rigidbody, CWPacejka pacejkaParam,
                   Transform wheelMeshParam, float _restLength, float _springTravel, float _springStiffness, float _springDamping, float _wheelRadius, float _wheelMass)
    {
        wheelColliderAdv = _wheelColliderAdv;
        transform        = _transform;
        wheelMesh        = wheelMeshParam;
        rb      = rigidbody;
        pacejka = pacejkaParam;

        restLength      = _restLength;
        springTravel    = _springTravel;
        springStiffness = _springStiffness;
        springDamping   = _springDamping;
        wheelRadius     = _wheelRadius;
        wheelMass       = _wheelMass;

        maxWheelVelocity    = 20f;
        maxWheelVelocityAcc = 10f;
        antiRollStiffness   = 0f;
        applyForceGround    = true;
        smoothStep          = true;

        slowCorrectionStart = 0.11f;
        slowCorrectionForce = 0.1f;

        wheelSphereJumpThreshold         = 0.05f;
        wheelSphereJumpMaxAngle          = 30f;
        wheelSphereJumpMinAngleNormals   = 5f;
        wheelSphereJumpMinGroundTime     = 0f;
        wheelSphereJumpNormalDistanceMin = 0.05f;
        wheelMaxForce = 10000000f;
        wheelMaxA     = 10f;

        angularVelocity = 0f;
        fcSide          = 1f;



        //Start

        minLength = restLength - springTravel;
        maxLength = restLength + springTravel;

        springLength    = restLength;
        springLength    = Mathf.Clamp(springLength, minLength, maxLength);
        springLengthOld = springLength;

        if (smoothStep)
        {
            GameObject instSphere = null;
            if (wheelSphere == null)
            {
                instSphere = new GameObject("(Inst) Car Sphere");
            }
            else
            {
                instSphere = wheelSphere.gameObject;
            }
            CapsuleCollider sc = instSphere.AddComponent <CapsuleCollider>();
            sc.radius              = 0.5f;
            sc.direction           = 0;
            sc.height              = 3f;
            wheelSphere            = instSphere.transform;
            wheelSphere.localScale = new Vector3(wheelRadius * 2f, wheelRadius * 2f, wheelRadius * 2f);

            wheelSphere.position = new Vector3(0f, -10000f, 0f);
        }
    }