コード例 #1
0
    protected WheelData[] wheels;     // array with the wheel data

    // setup wheelcollider for given wheel data
    // wheel is the transform of the wheel
    // maxSteer is the angle in degrees the wheel can steer (0f for no steering)
    // motor if wheel is driven by engine or not
    WheelData SetWheelParams(Transform wheel, float maxSteer, JWheelType wheeltype)
    {
        if (wheel == null)
        {
            throw new System.Exception("wheel not connected to script!");
        }
        WheelData result = new WheelData();         // the container of wheel specific data

        // we create a new gameobject for the collider and move, transform it to match
        // the position of the wheel it represents. This allows us to do transforms
        // on the wheel itself without disturbing the collider.
        GameObject go = new GameObject("WheelCollider");

        go.transform.parent   = transform;       // the car, not the wheel is parent
        go.transform.position = wheel.position;  // match wheel pos

        // create the actual wheel collider in the collider game object
        WheelCollider col = (WheelCollider)go.AddComponent(typeof(WheelCollider));

        col.motorTorque = 0.0f;

        // store some useful references in the wheeldata object
        result.transform = wheel;                      // access to wheel transform
        result.go        = go;                         // store the collider game object
        result.col       = col;                        // store the collider self
        result.startPos  = go.transform.localPosition; // store the current local pos of wheel
        result.maxSteer  = maxSteer;                   // store the max steering angle allowed for wheel
        result.wheeltype = wheeltype;                  // store if wheel is connected to engine


        // see docs, haven't really managed to get this work
        // like i would but just try out a fiddle with it.
        WheelFrictionCurve fc = col.forwardFriction;

        // fc.asymptoteValue = 5000.0f;
        // fc.extremumSlip = 2.0f;
        // fc.asymptoteSlip = 20.0f;
        fc.stiffness        = (wheeltype == JWheelType.Front)?fwdStiffnessFront:fwdStiffnessBack;
        col.forwardFriction = fc;
        fc = col.sidewaysFriction;
        // fc.asymptoteValue = 7500.0f;
        // fc.asymptoteSlip = 2.0f;
        fc.stiffness         = (wheeltype == JWheelType.Front)?swyStiffnessFront:swyStiffnessBack;
        col.sidewaysFriction = fc;

        return(result);        // return the WheelData
    }
コード例 #2
0
ファイル: JCar.cs プロジェクト: Shipaaaa/Run-Shipa-run
    // setup wheelcollider for given wheel data
    // wheel is the transform of the wheel
    // maxSteer is the angle in degrees the wheel can steer (0f for no steering)
    // motor if wheel is driven by engine or not
    WheelData SetWheelParams(Transform wheel, float maxSteer, JWheelType wheeltype)
    {
        if (wheel == null) {
            throw new System.Exception("wheel not connected to script!");
        }
        WheelData result = new WheelData(); // the container of wheel specific data

        // we create a new gameobject for the collider and move, transform it to match
        // the position of the wheel it represents. This allows us to do transforms
        // on the wheel itself without disturbing the collider.
        GameObject go = new GameObject("WheelCollider");
        go.transform.parent = transform; // the car, not the wheel is parent
        go.transform.position = wheel.position; // match wheel pos

        // create the actual wheel collider in the collider game object
        WheelCollider col = (WheelCollider) go.AddComponent(typeof(WheelCollider));
        col.motorTorque = 0.0f;

        // store some useful references in the wheeldata object
        result.transform = wheel; // access to wheel transform
        result.go = go; // store the collider game object
        result.col = col; // store the collider self
        result.startPos = go.transform.localPosition; // store the current local pos of wheel
        result.maxSteer = maxSteer; // store the max steering angle allowed for wheel
        result.wheeltype = wheeltype; // store if wheel is connected to engine

        // see docs, haven't really managed to get this work
        // like i would but just try out a fiddle with it.
        WheelFrictionCurve fc = col.forwardFriction;
        // fc.asymptoteValue = 5000.0f;
        // fc.extremumSlip = 2.0f;
        // fc.asymptoteSlip = 20.0f;
        fc.stiffness = (wheeltype==JWheelType.Front)?fwdStiffnessFront:fwdStiffnessBack;
        col.forwardFriction = fc;
        fc = col.sidewaysFriction;
        // fc.asymptoteValue = 7500.0f;
        // fc.asymptoteSlip = 2.0f;
        fc.stiffness = (wheeltype==JWheelType.Front)?swyStiffnessFront:swyStiffnessBack;
        col.sidewaysFriction = fc;

        return result; // return the WheelData
    }