Beispiel #1
0
    void Awake()
    {
        //WheelCollider[] wheelColliders  = {wheelFR, wheelMR, wheelBR, wheelFL, wheelML, wheelBL} ;
        foreach (WheelCollider wheel in wheelColliders) {
            wheel.mass = Mass;
            wheel.suspensionDistance = Suspension_Distance;
            wheel.radius = Radius;

            newFrictionCurve = wheel.sidewaysFriction;

            newFrictionCurve.asymptoteSlip = SF_asymptote_slip;
            newFrictionCurve.asymptoteValue = SF_asymptote_value;
            newFrictionCurve.extremumSlip = SF_extremum_slip;
            newFrictionCurve.extremumValue = SF_extremum_value;
            newFrictionCurve.stiffness = SF_stiffness;
            wheel.sidewaysFriction = newFrictionCurve;

            newFrictionCurve = wheel.forwardFriction;

            newFrictionCurve.asymptoteSlip = FF_asymptote_slip;
            newFrictionCurve.asymptoteValue = FF_asymptote_value;
            newFrictionCurve.extremumSlip = FF_extremum_slip;
            newFrictionCurve.extremumValue = FF_extremum_value;
            newFrictionCurve.stiffness = FF_stiffness;
            wheel.forwardFriction = newFrictionCurve;

            JointSpring newSuspensionSpring = wheel.suspensionSpring;
            newSuspensionSpring.spring = SS_spring;
            newSuspensionSpring.damper = SS_damper;
            newSuspensionSpring.targetPosition = SS_targetPosition;
            wheel.suspensionSpring = newSuspensionSpring;
        }
    }
    // ----------------------------------------------------------------------------
    static void SelectedChangeWheelColliderSettings_Default1()
    {
        Object[] colliders = GetSelectedWheelColliders ();

            //Selection.objects = new Object[0];

            foreach (WheelCollider collider in colliders) {

            WheelFrictionCurve curve = new WheelFrictionCurve();

            curve.extremumSlip = 0.01f;

            curve.extremumValue = 1.0f;

            curve.asymptoteSlip = 0.04f;

            curve.asymptoteValue = 0.6f;

            curve.stiffness = 50000.0f;

            collider.forwardFriction = curve;

            collider.sidewaysFriction = curve;

        }
    }
        /// <summary>
        /// Read the data using the reader.
        /// </summary>
        /// <param name="reader">Reader.</param>
        public override object Read(ISaveGameReader reader)
        {
            UnityEngine.WheelFrictionCurve wheelFrictionCurve = new UnityEngine.WheelFrictionCurve();
            foreach (string property in reader.Properties)
            {
                switch (property)
                {
                case "extremumSlip":
                    wheelFrictionCurve.extremumSlip = reader.ReadProperty <System.Single> ();
                    break;

                case "extremumValue":
                    wheelFrictionCurve.extremumValue = reader.ReadProperty <System.Single> ();
                    break;

                case "asymptoteSlip":
                    wheelFrictionCurve.asymptoteSlip = reader.ReadProperty <System.Single> ();
                    break;

                case "asymptoteValue":
                    wheelFrictionCurve.asymptoteValue = reader.ReadProperty <System.Single> ();
                    break;

                case "stiffness":
                    wheelFrictionCurve.stiffness = reader.ReadProperty <System.Single> ();
                    break;
                }
            }
            return(wheelFrictionCurve);
        }
Beispiel #4
0
        private void Start()
        {
            car = transform.parent.GetComponent<CarController>();
            wheelCollider = GetComponent<Collider>() as WheelCollider;

            if (wheelModel != null)
            {
                originalWheelModelPosition = wheelModel.localPosition;
                transform.position = wheelModel.position; // - wheelCollider.suspensionDistance*0.5f*transform.up;
            }

            // store initial starting values of wheelCollider
            sidewaysFriction = wheelCollider.sidewaysFriction;
            forwardFriction = wheelCollider.forwardFriction;
            sidewaysStiffness = wheelCollider.sidewaysFriction.stiffness;
            forwardStiffness = wheelCollider.forwardFriction.stiffness;

            // nominal max rpm at Car's top speed (can be more if Car is rolling downhill!)
            MaxRpm = (car.MaxSpeed/(Mathf.PI*wheelCollider.radius*2))*60;

            // get a reference to the particle system for the tire smoke
            skidSmokeSystem = car.GetComponentInChildren<ParticleSystem>();
            rb = wheelCollider.attachedRigidbody;

            if (skidTrailsDetachedParent == null)
            {
                skidTrailsDetachedParent = new GameObject("Skid Trails - Detached").transform;
            }
        }
 /// <summary>
 /// Write the specified value using the writer.
 /// </summary>
 /// <param name="value">Value.</param>
 /// <param name="writer">Writer.</param>
 public override void Write(object value, ISaveGameWriter writer)
 {
     UnityEngine.WheelFrictionCurve wheelFrictionCurve = (UnityEngine.WheelFrictionCurve)value;
     writer.WriteProperty("extremumSlip", wheelFrictionCurve.extremumSlip);
     writer.WriteProperty("extremumValue", wheelFrictionCurve.extremumValue);
     writer.WriteProperty("asymptoteSlip", wheelFrictionCurve.asymptoteSlip);
     writer.WriteProperty("asymptoteValue", wheelFrictionCurve.asymptoteValue);
     writer.WriteProperty("stiffness", wheelFrictionCurve.stiffness);
 }
Beispiel #6
0
 WheelFrictionCurve cloneCurve(WheelFrictionCurve curve, float newStiffness)
 {
     WheelFrictionCurve newCurve = new WheelFrictionCurve();
     newCurve.extremumSlip = curve.extremumSlip;
     newCurve.extremumValue = curve.extremumValue;
     newCurve.asymptoteSlip = curve.asymptoteSlip;
     newCurve.asymptoteValue = curve.asymptoteValue;
     newCurve.stiffness = newStiffness;
     return newCurve;
 }
Beispiel #7
0
 public WheelFrictionCurve setupWheelFriction()
 {
     WheelFrictionCurve wfc = new WheelFrictionCurve();
     wfc.asymptoteSlip = m_asymptoteSlip;
     wfc.asymptoteValue = m_asymptoteValue;
     wfc.extremumSlip = m_extremumSlip;
     wfc.extremumValue = m_extremumValue;
     wfc.stiffness = m_stiffness;
     return wfc;
 }
Beispiel #8
0
    static public int set_stiffness(IntPtr l)
    {
        UnityEngine.WheelFrictionCurve o = (UnityEngine.WheelFrictionCurve)checkSelf(l);
        float v;

        checkType(l, 2, out v);
        o.stiffness = v;
        setBack(l, o);
        return(0);
    }
Beispiel #9
0
    static public int set_extremumSlip(IntPtr l)
    {
        UnityEngine.WheelFrictionCurve o = (UnityEngine.WheelFrictionCurve)checkSelf(l);
        float v;

        checkType(l, 2, out v);
        o.extremumSlip = v;
        setBack(l, o);
        return(0);
    }
Beispiel #10
0
    static public int set_asymptoteValue(IntPtr l)
    {
        UnityEngine.WheelFrictionCurve o = (UnityEngine.WheelFrictionCurve)checkSelf(l);
        float v;

        checkType(l, 2, out v);
        o.asymptoteValue = v;
        setBack(l, o);
        return(0);
    }
 public static int constructor(IntPtr l)
 {
     try {
         UnityEngine.WheelFrictionCurve o;
         o=new UnityEngine.WheelFrictionCurve();
         pushValue(l,o);
         return 1;
     }
     catch(Exception e) {
         LuaDLL.luaL_error(l, e.ToString());
         return 0;
     }
 }
 static public int constructor(IntPtr l)
 {
     try {
         UnityEngine.WheelFrictionCurve o;
         o = new UnityEngine.WheelFrictionCurve();
         pushValue(l, true);
         pushValue(l, o);
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
 public static int constructor(IntPtr l)
 {
     try {
         UnityEngine.WheelFrictionCurve o;
         o=new UnityEngine.WheelFrictionCurve();
         pushValue(l,true);
         pushValue(l,o);
         return 2;
     }
     catch(Exception e) {
         return error(l,e);
     }
 }
 static public int constructor(IntPtr l)
 {
     try {
         UnityEngine.WheelFrictionCurve o;
         o = new UnityEngine.WheelFrictionCurve();
         pushValue(l, o);
         return(1);
     }
     catch (Exception e) {
         LuaDLL.luaL_error(l, e.ToString());
         return(0);
     }
 }
Beispiel #15
0
 static void WheelCollider_sidewaysFriction(JSVCall vc)
 {
     if (vc.bGet)
     {
         UnityEngine.WheelCollider _this = (UnityEngine.WheelCollider)vc.csObj;
         var result = _this.sidewaysFriction;
         JSMgr.datax.setObject((int)JSApi.SetType.Rval, result);
     }
     else
     {
         UnityEngine.WheelFrictionCurve arg0  = (UnityEngine.WheelFrictionCurve)JSMgr.datax.getObject((int)JSApi.GetType.Arg);
         UnityEngine.WheelCollider      _this = (UnityEngine.WheelCollider)vc.csObj;
         _this.sidewaysFriction = arg0;
     }
 }
Beispiel #16
0
 //in dieser Methode werden die WheelFrictionCurves übergeben, man kann sie auch noch nachträlich ändern, z.B. im beim
 //benutzen der Handbremse oder bei einen anderen Untergrund ein anderes Verhalten zu haben
 public void setFrictionCurves(WheelFrictionCurve forward, WheelFrictionCurve sideways)
 {
     //falls sich das Rad in der Luft befindet soll es nicht zur Berechnung beitragen
     WheelHit hit;
     if(wheelCol.GetGroundHit(out hit))
     {
         //schau auf welcher Layer der Refien fährt
         int layer = hit.collider.transform.gameObject.layer;
         //switch erlaubt keine abfragen wie "case LayerMask.NameToLayer("Default"):", daher feste Werte
         //Compiler Error CS0150: A constant value is expected
         switch(layer)
         {
         case 9:
             forward.stiffness *= 0.8f; //fester Sand, SandNormal
             sideways.stiffness *= 0.8f;
             checkSkidmarkLayer(layer);
             break;
         case 10:
             forward.stiffness *= 0.5f; //loser Sand, SandLose
             sideways.stiffness *= 1.5f;
             checkSkidmarkLayer(layer);
             break;
         case 11:
             forward.stiffness *= 0.75f; //Schotter, Rubble
             sideways.stiffness *= 0.65f;
             checkSkidmarkLayer(layer);
             break;
         case 12:
             forward.stiffness *= 0.8f; //Erdweg, Dirt
             sideways.stiffness *= 0.7f;
             checkSkidmarkLayer(layer);
             break;
         case 13:
             forward.stiffness *= 0.7f; //Grass, Grass
             sideways.stiffness *= 0.7f;
             checkSkidmarkLayer(layer);
             break;
         default:
             //asphalt, Default Layer (mach nichts)
             checkSkidmarkLayer(layer);
             break;
         }
         wheelCol.forwardFriction = forward;
         wheelCol.sidewaysFriction = sideways;
     }
     wheelCol.forwardFriction = forward;
     wheelCol.sidewaysFriction = sideways;
 }
 static void WheelFrictionCurve_asymptoteValue(JSVCall vc)
 {
     if (vc.bGet)
     {
         UnityEngine.WheelFrictionCurve _this = (UnityEngine.WheelFrictionCurve)vc.csObj;
         var result = _this.asymptoteValue;
         JSApi.setSingle((int)JSApi.SetType.Rval, (System.Single)(result));
     }
     else
     {
         System.Single arg0 = (System.Single)JSApi.getSingle((int)JSApi.GetType.Arg);
         UnityEngine.WheelFrictionCurve _this = (UnityEngine.WheelFrictionCurve)vc.csObj;
         _this.asymptoteValue = arg0;
         JSMgr.changeJSObj(vc.jsObjID, _this);
     }
 }
Beispiel #18
0
	// Use this for initialization
	void Start () {

		foreach (WheelCollider wheelCollider in wheelColliders) {
			WheelFrictionCurve wfc = new WheelFrictionCurve ();
			wfc.extremumSlip = forwardFrictionExtremeSlip;
			wfc.extremumValue = forwardFrictionExtremeVal;
			wfc.asymptoteSlip = forwardFrictionAsympSlip;
			wfc.asymptoteValue = forwardFrictionAsympVal;
			wfc.stiffness = forwardFrictionStiffness;
			wheelCollider.forwardFriction = wfc;

			WheelFrictionCurve wfc2 = new WheelFrictionCurve ();
			wfc2.extremumSlip = sidewaysFrictionExtremeSlip;
			wfc2.extremumValue = sidewaysFrictionExtremeVal;
			wfc2.asymptoteSlip = sidewaysFrictionAsympSlip;
			wfc2.asymptoteValue = sidewaysFrictionAsympVal;
			wfc2.stiffness = sidewaysFrictionStiffness;
			wheelCollider.sidewaysFriction = wfc2;
		}
	}
Beispiel #19
0
 static public int get_stiffness(IntPtr l)
 {
     UnityEngine.WheelFrictionCurve o = (UnityEngine.WheelFrictionCurve)checkSelf(l);
     pushValue(l, o.stiffness);
     return(1);
 }
        public void setDefaultValues()
        {
            if (carAxiles.Count < 1)
            {
                CustomDebug.customLog("CarControllerInspector", "setDefaultValues()", "Car axiles are missing.");
                return;
            }

            carData.setDefaultValues();

            foreach (CarAxile carAxile in carAxiles)
            {
                JointSpring tempSpring = new JointSpring();
                WheelFrictionCurve tempWheelFrictCurveForward = new WheelFrictionCurve();
                WheelFrictionCurve tempWheelFrictCurveSide = new WheelFrictionCurve();

                //Left wheel
                carAxile.leftWheel.mass = carData.mass;
                carAxile.leftWheel.radius = carData.radius;
                carAxile.leftWheel.wheelDampingRate = carData.dampingRate;
                carAxile.leftWheel.suspensionDistance = carData.suspensionDistance;
                carAxile.leftWheel.forceAppPointDistance = carData.forceAppPointDistance;

                tempSpring.spring = carData.spring;
                tempSpring.damper = carData.damper;
                tempSpring.targetPosition = carData.targetPosition;
                carAxile.leftWheel.suspensionSpring = tempSpring;

                tempWheelFrictCurveForward.extremumSlip = carData.forwardExtremumSlip;
                tempWheelFrictCurveForward.extremumValue = carData.forwardExtremumValue;
                tempWheelFrictCurveForward.asymptoteSlip = carData.forwardAsymptoteSlip;
                tempWheelFrictCurveForward.asymptoteValue = carData.forwardAsymptoteValue;
                tempWheelFrictCurveForward.stiffness = carData.forwardStiffness;

                tempWheelFrictCurveSide.extremumSlip = carData.sideExtremumSlip;
                tempWheelFrictCurveSide.extremumValue = carData.sideExtremumValue;
                tempWheelFrictCurveSide.asymptoteSlip = carData.sideAsymptoteSlip;
                tempWheelFrictCurveSide.asymptoteValue = carData.sideAsymptoteValue;
                tempWheelFrictCurveSide.stiffness = carData.sideStiffness;

                carAxile.leftWheel.forwardFriction = tempWheelFrictCurveForward;
                carAxile.leftWheel.sidewaysFriction = tempWheelFrictCurveSide;

                //Right wheel
                carAxile.rightWheel.mass = carData.mass;
                carAxile.rightWheel.radius = carData.radius;
                carAxile.rightWheel.wheelDampingRate = carData.dampingRate;
                carAxile.rightWheel.suspensionDistance = carData.suspensionDistance;
                carAxile.rightWheel.forceAppPointDistance = carData.forceAppPointDistance;

                tempSpring.spring = carData.spring;
                tempSpring.damper = carData.damper;
                tempSpring.targetPosition = carData.targetPosition;
                carAxile.rightWheel.suspensionSpring = tempSpring;

                tempWheelFrictCurveForward.extremumSlip = carData.forwardExtremumSlip;
                tempWheelFrictCurveForward.extremumValue = carData.forwardExtremumValue;
                tempWheelFrictCurveForward.asymptoteSlip = carData.forwardAsymptoteSlip;
                tempWheelFrictCurveForward.asymptoteValue = carData.forwardAsymptoteValue;
                tempWheelFrictCurveForward.stiffness = carData.forwardStiffness;

                tempWheelFrictCurveSide.extremumSlip = carData.sideExtremumSlip;
                tempWheelFrictCurveSide.extremumValue = carData.sideExtremumValue;
                tempWheelFrictCurveSide.asymptoteSlip = carData.sideAsymptoteSlip;
                tempWheelFrictCurveSide.asymptoteValue = carData.sideAsymptoteValue;
                tempWheelFrictCurveSide.stiffness = carData.sideStiffness;

                carAxile.rightWheel.forwardFriction = tempWheelFrictCurveForward;
                carAxile.rightWheel.sidewaysFriction = tempWheelFrictCurveSide;
            }
            CustomDebug.customLog("CarControllerInspector", "setDefaultValues()", "CarData default values and wheel colliders are set.");
        }
    void Start()
    {
        wheelCollider = GetComponent<WheelCollider>();
        carController = transform.root.GetComponent<RCCCarControllerV2>();
        carRigid = carController.GetComponent<Rigidbody>();

        if(FindObjectOfType(typeof(RCCSkidmarks)))
            skidmarks = FindObjectOfType(typeof(RCCSkidmarks)) as RCCSkidmarks;
        else
            Debug.Log("No skidmarks object found. Skidmarks will not be drawn. Drag ''RCCSkidmarksManager'' from Prefabs folder, and drop on to your existing scene...");

        grassPhysicsMaterial = Resources.Load("RCCGrassPhysics") as PhysicMaterial;
        sandPhysicsMaterial = Resources.Load("RCCSandPhysics") as PhysicMaterial;

        forwardFrictionCurve = GetComponent<WheelCollider>().forwardFriction;
        sidewaysFrictionCurve = GetComponent<WheelCollider>().sidewaysFriction;

        defForwardStiffness = forwardFrictionCurve.stiffness;
        defSidewaysStiffness = sidewaysFrictionCurve.stiffness;
    }
Beispiel #22
0
 private extern void INTERNAL_get_sidewaysFriction(out WheelFrictionCurve value);
 private void INTERNAL_set_forwardFriction(ref WheelFrictionCurve value);
Beispiel #24
0
    // ----------------------------------------------------------------------------------
    // Name	:	SetupWheelFrictionCurve
    // Desc	:	Sets up all the wheel friction curves used by
    //            our wheels to turn slip force into traction force
    // ----------------------------------------------------------------------------------
    void SetupWheelFrictionCurve()
    {
        // This controls the laterial friction of our wheels
        sidewaysWFC = new WheelFrictionCurve();
        //        sidewaysWFC.extremumSlip = 1;
        //        sidewaysWFC.extremumValue = 350;
        //        sidewaysWFC.asymptoteSlip = 2;
        //        sidewaysWFC.asymptoteValue = 150;
        sidewaysWFC.extremumSlip = 1f;
        sidewaysWFC.extremumValue = 6000;
        sidewaysWFC.asymptoteSlip = 2.0f;
        sidewaysWFC.asymptoteValue = 400;

        // This controls our normal longitudinal friction
        forwardsWFC = new WheelFrictionCurve();
        //        forwardsWFC.extremumSlip = 0.5f;
        //        forwardsWFC.extremumValue = 6000;
        //        forwardsWFC.asymptoteSlip = 2.0f;
        //        forwardsWFC.asymptoteValue = 400;
        forwardsWFC.extremumSlip = 1f;
        forwardsWFC.extremumValue = 20000;
        forwardsWFC.asymptoteSlip = 2.0f;
        forwardsWFC.asymptoteValue = 10000;
        forwardsWFC.stiffness = 0.82f;

        // I swap this friction curve for the normal forwards curve
        // when the car is braking.
        brakeWFC = new WheelFrictionCurve();
        brakeWFC.extremumSlip = 1;
        brakeWFC.extremumValue = 500;
        brakeWFC.asymptoteSlip = 2;
        brakeWFC.asymptoteValue = 250;
        brakeWFC.stiffness = 1.0f;

        // Handbrake friction curve for the rear wheels, to make the car drift easier while handbraking
        handbrakeRWFC = new WheelFrictionCurve();
        handbrakeRWFC.extremumSlip = 1;
        handbrakeRWFC.extremumValue = 350;
        handbrakeRWFC.asymptoteSlip = 2;
        handbrakeRWFC.asymptoteValue = 150;

        // Handbrake friction curve for the rear wheels, to make the car drift easier while handbraking
        handbrakeFWFC = new WheelFrictionCurve();
        handbrakeFWFC.extremumSlip = 1;
        handbrakeFWFC.extremumValue = 350;
        handbrakeFWFC.asymptoteSlip = 2;
        handbrakeFWFC.asymptoteValue = 150;
        handbrakeFWFC.stiffness = 0.3f;
    }
Beispiel #25
0
 void SetupWheelFrictionCurve()
 {
     wfc = new WheelFrictionCurve();
     wfc.extremumSlip = 1;
     wfc.extremumValue = 50;
     wfc.asymptoteSlip = 2;
     wfc.asymptoteValue = 25;
     wfc.stiffness = 1;
 }
Beispiel #26
0
    void Start()
    {
        frForwardFriction = frWheelCollider.forwardFriction;
        flForwardFriction = flWheelCollider.forwardFriction;
        rrForwardFriction = rrWheelCollider.forwardFriction;
        rlForwardFriction = rlWheelCollider.forwardFriction;

        frSidewaysFriction = frWheelCollider.sidewaysFriction;
        flSidewaysFriction = flWheelCollider.sidewaysFriction;
        rrSidewaysFriction = rrWheelCollider.sidewaysFriction;
        rlSidewaysFriction = rlWheelCollider.sidewaysFriction;
    }
Beispiel #27
0
    void Start()
    {
        //Destroy existing rigidbody, we don't want anyone to mess with it.
        if(rigidbody)
            Destroy(rigidbody);

        //setup rigidbody
        gameObject.AddComponent<Rigidbody>();
        rigidbody.mass = mass;
        rigidbody.drag = drag;
        rigidbody.angularDrag = 0.05f;
        rigidbody.centerOfMass = new Vector3(rigidbody.centerOfMass.x, cogY, rigidbody.centerOfMass.z);
        rigidbody.interpolation = RigidbodyInterpolation.Interpolate;
        //		rigidbody.constraints = RigidbodyConstraints.FreezeRotationZ;

        //start engine noise
        audio.loop = true;
        audio.Play();
        SMCamera = Camera.main.GetComponent<SmoothFollow>();
        //setup wheels
        wheels=new WheelData[4 + otherWheels.Length];
        for(int i=0;i<4 + otherWheels.Length;i++)
            wheels[i] = new WheelData();

        wheels[0].graphic = wheelFL;
        wheels[1].graphic = wheelFR;
        wheels[2].graphic = wheelBL;
        wheels[3].graphic = wheelBR;
        for(int i=0;i < otherWheels.Length;i++)
        {
            wheels[i + 4].graphic = otherWheels[i];
        }
        wheels[0].maxSteerAngle = 30.0f;
        wheels[1].maxSteerAngle = 30.0f;
        wheels[2].powered = true;
        wheels[3].powered = true;
        wheels[2].handbraked = true;
        wheels[3].handbraked = true;

        foreach(WheelData w in wheels)
        {
            if(w.graphic == null)
                Debug.Log("You need to assign all four wheels for the car script!");
            if(!w.graphic.transform.IsChildOf(transform))
                Debug.Log("Wheels need to be children of the Object with the car script");

            w.originalRotation = w.graphic.localRotation;

            //create collider
            GameObject colliderObject = new GameObject("WheelCollider");
            colliderObject.transform.parent = transform;
            colliderObject.transform.localPosition = w.graphic.localPosition;
            colliderObject.transform.localRotation = w.graphic.localRotation;
            w.coll = colliderObject.AddComponent<WheelCollider>();
            w.coll.suspensionDistance = suspensionDistance;
            JointSpring js = new JointSpring();
            js.spring = springs;
            js.damper = dampers;
        //			w.coll.suspensionSpring.spring = springs;
        //			w.coll.suspensionSpring.damper = dampers;
            w.coll.suspensionSpring = js;
            //no grip, as we simulate handling ourselves
            WheelFrictionCurve forwardwfc = new WheelFrictionCurve();
            forwardwfc.stiffness = 0;
            WheelFrictionCurve sidewaywfc = new WheelFrictionCurve();
            sidewaywfc.stiffness = 0;
        //			w.coll.forwardFriction.stiffness = 0;
        //			w.coll.sidewaysFriction.stiffness = 0;
            w.coll.forwardFriction = forwardwfc;
            w.coll.sidewaysFriction = sidewaywfc;
            w.coll.radius = wheelRadius;
        }

        //get wheel height (height forces are applied on)
        //		wheelY = wheels[0].graphic.localPosition.y;

        //find skidmark object
        skidmarks = FindObjectOfType(typeof(Skidmarks)) as Skidmarks;

        //shift to first
        gear = 1;
        defaultMaxRPM = maxRPM;
        defaultMaxTorque = maxTorque;
        carAI = GetComponent<CarAI>();
    }
Beispiel #28
0
 private extern void INTERNAL_set_forwardFriction(ref WheelFrictionCurve value);
Beispiel #29
0
 public WheelFrictionChanger(Wheel w)
 {
     Collider = w.whCollider;
     forwardFriction  = Collider.forwardFriction;
     sidewaysFriction = Collider.sidewaysFriction;
 }
 private void INTERNAL_set_sidewaysFriction(ref WheelFrictionCurve value);
Beispiel #31
0
    //diese Methode initialisiert alle WheelFrictionCurves
    private void setupWFC()
    {
        //normales geradeaus fahren
        forwardWFC = new WheelFrictionCurve();
        forwardWFC.asymptoteSlip = 2.0f;
        forwardWFC.asymptoteValue = 200; //400f;
        forwardWFC.extremumSlip = 0.5f;
        forwardWFC.extremumValue = 3000; //6000;
        forwardWFC.stiffness = 1.0f;

        //seitliches rutschen/bewegen für die Vorderreifen
        sidewaysFrontWFC = new WheelFrictionCurve();
        sidewaysFrontWFC.asymptoteSlip = 2.0f;
        sidewaysFrontWFC.asymptoteValue = 70; //150f;
        sidewaysFrontWFC.extremumSlip = 1f;
        sidewaysFrontWFC.extremumValue = 170; //350;
        sidewaysFrontWFC.stiffness = 1.0f * slipMultiplier;

        //seitliches rutschen/bewegen für die Hintereifen (für Donuts usw.)
        sidewaysRearWFC = new WheelFrictionCurve();
        sidewaysRearWFC.asymptoteSlip = 2.0f;
        sidewaysRearWFC.asymptoteValue = 70; //150f;
        sidewaysRearWFC.extremumSlip = 1f;
        sidewaysRearWFC.extremumValue = 170; //350;
        sidewaysRearWFC.stiffness = 0.9f * slipMultiplier;

        //seitliches rutschen falls die Handbremse benutzt wird
        sidewaysHandbrakeWFC = new WheelFrictionCurve();
        sidewaysHandbrakeWFC.asymptoteSlip = 2.0f;
        sidewaysHandbrakeWFC.asymptoteValue = 70; //150f;
        sidewaysHandbrakeWFC.extremumSlip = 1f;
        sidewaysHandbrakeWFC.extremumValue = 200; //350;
        sidewaysHandbrakeWFC.stiffness = 1.0f;
    }
Beispiel #32
0
    WheelFrictionCurve SetupWheelFrictionCurve()
    {
        WheelFrictionCurve wfc = new WheelFrictionCurve();
        wfc.extremumSlip = 1;
        wfc.extremumValue = 50000;
        wfc.asymptoteSlip = 20;
        wfc.asymptoteValue = 50000;
        wfc.stiffness = 4;

        return wfc;
    }
    void Start()
    {
        wheelCollider = GetComponent<WheelCollider>();
        carController = GetComponentInParent<RCCCarControllerV2>();
        carRigid = carController.GetComponent<Rigidbody>();

        if(FindObjectOfType(typeof(RCCSkidmarks)))
            skidmarks = FindObjectOfType(typeof(RCCSkidmarks)) as RCCSkidmarks;
        else
            Debug.Log("No skidmarks object found. Skidmarks will not be drawn. Drag ''RCCSkidmarksManager'' from Prefabs folder, and drop on to your existing scene...");

        forwardFrictionCurve = GetComponent<WheelCollider>().forwardFriction;
        sidewaysFrictionCurve = GetComponent<WheelCollider>().sidewaysFriction;
    }
    void Update()
    {
        rigidbody.drag = rigidbody.velocity.magnitude / 250;
        float mph = rigidbody.velocity.magnitude * 2.237f;
        mphDisplay.text = "MPH: " + mph.ToString("F0");

        float fwdSpeed= rigidbody.velocity.magnitude;
        float highSpeedFraction= fwdSpeed / highSpeedLevel;
        float actualSteerAngle= Mathf.Lerp(lowSpeedSteer, highSpeedSteer, highSpeedFraction);

        fl.localEulerAngles = new Vector3(0,FrontLeftWheel.steerAngle - fl.localEulerAngles.z, 0);
        fr.localEulerAngles = new Vector3(0,FrontRightWheel.steerAngle - fr.localEulerAngles.z, 0);
        /////////////////////////////************************Joystick Code**************************////////////////////////////////////////
         //Debug.Log(joystickPos.position.x);

         	if(joystickPos.position.x < 0)
         	{
         		FrontLeftWheel.steerAngle = -actualSteerAngle;
                FrontRightWheel.steerAngle = -actualSteerAngle;
            }

         	else if(joystickPos.position.x > 0)
         	{
         		FrontLeftWheel.steerAngle = actualSteerAngle;
                FrontRightWheel.steerAngle = actualSteerAngle;
         	}

         		else
         		{
         			FrontLeftWheel.steerAngle = 0;
                FrontRightWheel.steerAngle = 0;
         		}

        ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        // limit the maimum speed of the car by imposing drag
        rigidbody.drag = rigidbody.velocity.magnitude / 250;

        foreach(Touch touch in Input.touches)
        {

        if (gasButton.HitTest (touch.position) && touch.phase == TouchPhase.Stationary){
            motorInputTouch = 1;
            //Debug.Log ("Hitting the Gas Button");
        }
        else if (touch.phase == TouchPhase.Ended)
        {
            //Debug.Log("Lifted off the gas");
            motorInputTouch = 0;
            if(motorInputTouch == 0)
                {
                    rigidbody.velocity = rigidbody.velocity * 0.995f;
                }
        }

        if ( brakeButton.HitTest (touch.position) && touch.phase == TouchPhase.Stationary)
        {
            brakePower = 200;
            //if(this.rigidbody.velocity.z >= 0.0f && !reverse)
            if(touch.tapCount==1)
            {
                brakePower = 0;
                motorInputTouch = -1;
            }
        }

        else if (touch.phase == TouchPhase.Moved)
        {
            brakePower = 0;

        }

        if (handBrake.HitTest (touch.position) && touch.phase == TouchPhase.Stationary)
        {
            RearRightWheel.brakeTorque = 200.0f;
            RearLeftWheel.brakeTorque = 200.0f;
            WheelFrictionCurve temp1 = new WheelFrictionCurve();
            temp1 = RearRightWheel.sidewaysFriction;
            temp1.extremumSlip = 100.0f;
            RearRightWheel.sidewaysFriction = temp1;

            WheelFrictionCurve temp2 = new WheelFrictionCurve();
            temp2 = RearLeftWheel.sidewaysFriction;
            temp2.extremumSlip = 100.0f;
            RearLeftWheel.sidewaysFriction = temp2;
            //Debug.Log ("Handbrake on");

        }
        else if (touch.phase == TouchPhase.Ended)
        {
            RearRightWheel.brakeTorque = 0;
            RearLeftWheel.brakeTorque = 0;

            WheelFrictionCurve temp1 = new WheelFrictionCurve();
            temp1 = RearRightWheel.sidewaysFriction;
            temp1.extremumSlip = 1.0f;
            RearRightWheel.sidewaysFriction = temp1;

            WheelFrictionCurve temp2 = new WheelFrictionCurve();
            temp2 = RearLeftWheel.sidewaysFriction;
            temp2.extremumSlip = 1.0f;
            RearLeftWheel.sidewaysFriction = temp2;
            //Debug.Log("Handbrake off");

        }

        /*
        if (touch.phase == TouchPhase.Stationary && leftButton.HitTest (touch.position)){ //
            FrontLeftWheel.steerAngle = -actualSteerAngle;
            FrontRightWheel.steerAngle = -actualSteerAngle;
        }
        else if (touch.phase == TouchPhase.Ended){
            FrontLeftWheel.steerAngle = 0;
            FrontRightWheel.steerAngle = 0;
        }

        if (touch.phase == TouchPhase.Stationary && rightButton.HitTest (touch.position)){
            FrontLeftWheel.steerAngle = actualSteerAngle;
            FrontRightWheel.steerAngle = actualSteerAngle;
        }
        else if (touch.phase == TouchPhase.Ended){
            FrontLeftWheel.steerAngle = 0;
            FrontRightWheel.steerAngle = 0;
        }
        */

        //if (touch.phase == TouchPhase.Began && reverseButton.HitTest (touch.position)){
            //Application.Quit();
        //}

        }

        // Compute the engine RPM based on the average RPM of the two wheels, then call the shift gear function
        EngineRPM = (FrontLeftWheel.rpm + FrontRightWheel.rpm)/2 * GearRatio[CurrentGear];
        ShiftGears();

        // set the audio pitch to the percentage of RPM to the maximum RPM plus one, this makes the sound play
        // up to twice it's pitch, where it will suddenly drop when it switches gears.
        audio.pitch = Mathf.Abs(EngineRPM / MaxEngineRPM) + 0.5f ;
        // this line is just to ensure that the pitch does not reach a value higher than is desired.
        if ( audio.pitch > 2.0f ) {
        audio.pitch = 2.0f;
        }

        // finally, apply the values to the wheels.	The torque applied is divided by the current gear, and
        // multiplied by the user input variable.
        FrontLeftWheel.motorTorque = EngineTorque / GearRatio[CurrentGear] * motorInputTouch;
        FrontRightWheel.motorTorque = EngineTorque / GearRatio[CurrentGear] * motorInputTouch;
        RearRightWheel.brakeTorque = brakePower;
        RearLeftWheel.brakeTorque = brakePower;
        // the steer angle is an arbitrary value multiplied by the user input.
        //FrontLeftWheel.steerAngle = 30 * Input.GetAxis("Horizontal");

        //FrontRightWheel.steerAngle = 30 * Input.GetAxis("Horizontal");
    }
	public void CreateWheelColliders (){
		
		List <Transform> allWheelTransforms = new List<Transform>();
		allWheelTransforms.Add(FrontLeftWheelTransform); allWheelTransforms.Add(FrontRightWheelTransform); allWheelTransforms.Add(RearLeftWheelTransform); allWheelTransforms.Add(RearRightWheelTransform);
		
		if(allWheelTransforms[0] == null){
			Debug.LogError("You haven't choose your Wheel Transforms. Please select all of your Wheel Transforms before creating Wheel Colliders. Script needs to know their positions, aye?");
			return;
		}
		
		transform.rotation = Quaternion.identity;
		
		GameObject WheelColliders = new GameObject("Wheel Colliders");
		WheelColliders.transform.SetParent(transform);
		WheelColliders.transform.localRotation = Quaternion.identity;
		WheelColliders.transform.localPosition = Vector3.zero;
		WheelColliders.transform.localScale = Vector3.one;
		
		foreach(Transform wheel in allWheelTransforms){
			
			GameObject wheelcollider = new GameObject(wheel.transform.name); 
			
			wheelcollider.transform.position = wheel.transform.position;
			wheelcollider.transform.rotation = transform.rotation;
			wheelcollider.transform.name = wheel.transform.name;
			wheelcollider.transform.SetParent(WheelColliders.transform);
			wheelcollider.transform.localScale = Vector3.one;
			wheelcollider.AddComponent<WheelCollider>();
			wheelcollider.GetComponent<WheelCollider>().radius = (wheel.GetComponent<MeshRenderer>().bounds.extents.y) / transform.localScale.y;

			wheelcollider.AddComponent<RCCWheelCollider>();
			
			JointSpring spring = wheelcollider.GetComponent<WheelCollider>().suspensionSpring;

			spring.spring = 35000f;
			spring.damper = 1500f;

			wheelcollider.GetComponent<WheelCollider>().suspensionSpring = spring;
			wheelcollider.GetComponent<WheelCollider>().suspensionDistance = .2f;
			wheelcollider.GetComponent<WheelCollider>().forceAppPointDistance = .15f;
			wheelcollider.GetComponent<WheelCollider>().mass = 125f;
			wheelcollider.GetComponent<WheelCollider>().wheelDampingRate = 1f;
			
			sidewaysFriction = wheelcollider.GetComponent<WheelCollider>().sidewaysFriction;
			forwardFriction = wheelcollider.GetComponent<WheelCollider>().forwardFriction;

			forwardFriction.extremumSlip = .4f;
			forwardFriction.extremumValue = 1;
			forwardFriction.asymptoteSlip = .8f;
			forwardFriction.asymptoteValue = .75f;
			forwardFriction.stiffness = 1f;

			sidewaysFriction.extremumSlip = .25f;
			sidewaysFriction.extremumValue = 1;
			sidewaysFriction.asymptoteSlip = .5f;
			sidewaysFriction.asymptoteValue = .75f;
			sidewaysFriction.stiffness = 1f;

			wheelcollider.GetComponent<WheelCollider>().sidewaysFriction = sidewaysFriction;
			wheelcollider.GetComponent<WheelCollider>().forwardFriction = forwardFriction;

		}
		
		WheelCollider[] allWheelColliders = new WheelCollider[allWheelTransforms.Count];
		allWheelColliders = GetComponentsInChildren<WheelCollider>();
		
		FrontLeftWheelCollider = allWheelColliders[0];
		FrontRightWheelCollider = allWheelColliders[1];
		RearLeftWheelCollider = allWheelColliders[2];
		RearRightWheelCollider = allWheelColliders[3];
		
	}
    //    void OnCollisionStay(Collision col)
    //    {
    //        if (col.gameObject.CompareTag("OutWorld"))
    //        {
    //            if (col.contacts.Length>0)
    //                rigidbody.AddForce(col.contacts[0].normal*0.02f,ForceMode.Impulse);
    //        }
    //
    //        if (!col.gameObject.CompareTag("Road") && !col.gameObject.CompareTag("Ground") && col.relativeVelocity.magnitude>15f)
    //            if (Time.time - _lastDTime > 5)
    //        {
    //            Lifes--;
    //            EventController.PostEvent("update.car.health",gameObject);
    //            if (Lifes>=0)
    //                StartCoroutine("Immortal");
    //            else
    //                EventController.PostEvent("car.player.death",gameObject);
    //            _lastDTime = Time.time;
    //        }
    //    }
    void OnCollisionExit(Collision col)
    {
        if (col.gameObject.CompareTag("Ground"))
        {
            _driver.MaxSpeed = _maxSpeed;

            WheelFrictionCurve curve = new WheelFrictionCurve();
            curve.extremumSlip = 1;
            curve.extremumValue = 20000;
            curve.asymptoteSlip = 2;
            curve.asymptoteValue = 10000;
            curve.stiffness = 1;
            foreach(WheelCollider wcol in _cols)
                wcol.sidewaysFriction = curve;
        }
    }
Beispiel #37
0
    public void updateWheelFriction()
    {
        WheelFrictionCurve forwardFriction = new WheelFrictionCurve();
        forwardFriction.extremumSlip = forwardsExtremumSlip;
        forwardFriction.extremumValue = forwardsExtremumValue;
        forwardFriction.asymptoteSlip = forwardsAsymptoteSlip;
        forwardFriction.asymptoteValue = forwardsAsymptoteValue;
        forwardFriction.stiffness = forwardStiffness;

        WheelFrictionCurve sidewaysFriction = new WheelFrictionCurve();
        sidewaysFriction.extremumSlip = sidewaysExtremumSlip;
        sidewaysFriction.extremumValue = sidewaysExtremumValue;
        sidewaysFriction.asymptoteSlip = sidewaysAsymptoteSlip;
        sidewaysFriction.asymptoteValue = sidewaysAsymptoteValue;
        sidewaysFriction.stiffness = sidewaysStiffness;

        for (int i = 0; i < wheels.Count; i++)
        {
            wheels[i].wheelCollider.forwardFriction = forwardFriction;
            wheels[i].wheelCollider.sidewaysFriction = sidewaysFriction;
        }
    }
Beispiel #38
0
 static public int get_extremumSlip(IntPtr l)
 {
     UnityEngine.WheelFrictionCurve o = (UnityEngine.WheelFrictionCurve)checkSelf(l);
     pushValue(l, o.extremumSlip);
     return(1);
 }
Beispiel #39
0
 private extern void INTERNAL_set_sidewaysFriction(ref WheelFrictionCurve value);
Beispiel #40
0
    void UpdateFriction(Vector3 relativeVelocity)
    {
        float sqrVel = relativeVelocity.x * relativeVelocity.x * slipFactor;

        // Add extra sideways friction based on the car's turning velocity to avoid slipping
        extremum = Mathf.Clamp(300 - sqrVel, 0, 300);
        asymptote =Mathf.Clamp(150 - (sqrVel / 2), 0, 150);

        foreach (WheelCollider w in wheelColliders)
        {
            wfc = w.sidewaysFriction;
            wfc.extremumValue = extremum;
            wfc.asymptoteValue = asymptote;
            w.sidewaysFriction = wfc;

            wfc = w.forwardFriction;
            wfc.extremumValue = extremum;
            wfc.asymptoteValue = asymptote;
            w.forwardFriction = wfc;

        }
    }
 private void INTERNAL_get_forwardFriction(out WheelFrictionCurve value);
Beispiel #42
0
 static public int get_asymptoteValue(IntPtr l)
 {
     UnityEngine.WheelFrictionCurve o = (UnityEngine.WheelFrictionCurve)checkSelf(l);
     pushValue(l, o.asymptoteValue);
     return(1);
 }
 private void INTERNAL_get_sidewaysFriction(out WheelFrictionCurve value);
Beispiel #44
0
    // --------------------------- Start ---------------------------------------------------------------------
    public void Start()
    {
        foreach (Transform child in transform)
        {
            if(child.gameObject.name.Contains("wheel")){
                if (wheels == null)
                    wheels = new List<WheelSet>();
                WheelSet wheel=new WheelSet();
                if(child.gameObject.name.Contains("f")){
                    wheel.steered = true;
                }
                wheel.wheelgraphic=child;
                wheel.powered = true;
                wheel.handbraked = true;
                wheel.wheelaxle = child;
                wheels.Add(wheel);
            }
        }
        // wheels enumerator
        if (wheels != null)
        {
            WheelsN = wheels.Count;

            foreach (WheelSet w in wheels)
            {
                w.originalRotation = w.wheelgraphic.rotation;
                w.originalBrakeRotation = w.wheelaxle.rotation;

                //create collider
                GameObject colliderObject = new GameObject("WheelC");
                colliderObject.transform.parent = transform;
                colliderObject.transform.position = w.wheelgraphic.position;
                w.wCollider = colliderObject.AddComponent<WheelCollider>();
                w.wCollider.suspensionDistance = springLength;
                JointSpring springSetup = new JointSpring();
                springSetup.spring = springForce;
                springSetup.damper = damperForce;
                w.wCollider.suspensionSpring = springSetup;
                WheelFrictionCurve forFrictionSetup = new WheelFrictionCurve();
                WheelFrictionCurve sideFrictionSetup = new WheelFrictionCurve();

                forFrictionSetup.stiffness = FrontSlip;
                sideFrictionSetup.stiffness = SideSlip;
                w.wCollider.forwardFriction = forFrictionSetup;
                w.wCollider.sidewaysFriction = sideFrictionSetup;
                w.wCollider.mass = WheelMass;
                w.wCollider.radius = WheelRadius;
                if (w.powered)
                {
                    MWheelsN++;
                }
                CurrentGear = 0;
            }
            // mass center adjustment
            rigidbody.centerOfMass = massCorrection;
            Debug.Log(rigidbody.centerOfMass);
        }
        else
        {
            Debug.LogError("No wheels assigned!");
        }
        if (MWheelsN == 0)
        {
            Debug.Log("No motor wheels assigned!");
        }
    }
    // Convertir parámetros de fricción en una curva de WheelCollider
    WheelFrictionCurve GetWheelFrictionCurve(CarFrictionCurve Friction, float Stiffness, float SlipFactor)
    {
        WheelFrictionCurve Curve = new WheelFrictionCurve ();

        Curve.extremumSlip = 1.0f * SlipFactor;
        Curve.extremumValue = Friction.grip * m_DeltaTimeFactor;
        Curve.asymptoteSlip = (1.0f + Friction.gripRange) * SlipFactor;
        Curve.asymptoteValue = Friction.drift * m_DeltaTimeFactor;

        Curve.stiffness = Stiffness;
        return Curve;
    }
Beispiel #46
0
 private extern void INTERNAL_get_forwardFriction(out WheelFrictionCurve value);