static public int constructor(IntPtr l)
 {
     try {
                     #if DEBUG
         var    method     = System.Reflection.MethodBase.GetCurrentMethod();
         string methodName = GetMethodName(method);
                     #if UNITY_5_5_OR_NEWER
         UnityEngine.Profiling.Profiler.BeginSample(methodName);
                     #else
         Profiler.BeginSample(methodName);
                     #endif
                     #endif
         UnityEngine.WheelHit o;
         o = new UnityEngine.WheelHit();
         pushValue(l, true);
         pushValue(l, o);
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
             #if DEBUG
     finally {
                     #if UNITY_5_5_OR_NEWER
         UnityEngine.Profiling.Profiler.EndSample();
                     #else
         Profiler.EndSample();
                     #endif
     }
             #endif
 }
示例#2
0
    public void ApplyAntiRoll(Rigidbody rigidbody)
    {
        WheelHit hit = new WheelHit();
        float travelL = 1.0f;
        float travelR = 1.0f;

        bool groundedL = wheelL.collider.GetGroundHit(out hit);
        if (groundedL)
        {
            travelL = (-wheelL.collider.transform.InverseTransformPoint(hit.point).y - wheelL.radius) / wheelL.collider.suspensionDistance;
        }

        bool groundedR = wheelR.collider.GetGroundHit(out hit);
        if (groundedR)
        {
            travelR = (-wheelR.collider.transform.InverseTransformPoint(hit.point).y - wheelR.radius) / wheelR.collider.suspensionDistance;
        }

        float antiRollForce = (travelL - travelR) * antiRollValue;

        if (groundedL)
        {
            rigidbody.AddForceAtPosition(wheelL.collider.transform.up * -antiRollForce,
                                            wheelL.collider.transform.position);
        }

        if (groundedR)
        {
            rigidbody.AddForceAtPosition(wheelR.collider.transform.up * antiRollForce,
                  							 wheelR.collider.transform.position);
        }
    }
 static public int set_sidewaysDir(IntPtr l)
 {
     UnityEngine.WheelHit o = (UnityEngine.WheelHit)checkSelf(l);
     UnityEngine.Vector3  v;
     checkType(l, 2, out v);
     o.sidewaysDir = v;
     setBack(l, o);
     return(0);
 }
 static public int set_collider(IntPtr l)
 {
     UnityEngine.WheelHit o = (UnityEngine.WheelHit)checkSelf(l);
     UnityEngine.Collider v;
     checkType(l, 2, out v);
     o.collider = v;
     setBack(l, o);
     return(0);
 }
    static public int set_sidewaysSlip(IntPtr l)
    {
        UnityEngine.WheelHit o = (UnityEngine.WheelHit)checkSelf(l);
        float v;

        checkType(l, 2, out v);
        o.sidewaysSlip = v;
        setBack(l, o);
        return(0);
    }
    static public int set_force(IntPtr l)
    {
        UnityEngine.WheelHit o = (UnityEngine.WheelHit)checkSelf(l);
        float v;

        checkType(l, 2, out v);
        o.force = v;
        setBack(l, o);
        return(0);
    }
	static public int constructor(IntPtr l) {
		try {
			UnityEngine.WheelHit o;
			o=new UnityEngine.WheelHit();
			pushValue(l,true);
			pushValue(l,o);
			return 2;
		}
		catch(Exception e) {
			return error(l,e);
		}
	}
示例#8
0
 /// <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.WheelHit wheelHit = (UnityEngine.WheelHit)value;
     writer.WriteProperty("collider", wheelHit.collider);
     writer.WriteProperty("point", wheelHit.point);
     writer.WriteProperty("normal", wheelHit.normal);
     writer.WriteProperty("forwardDir", wheelHit.forwardDir);
     writer.WriteProperty("sidewaysDir", wheelHit.sidewaysDir);
     writer.WriteProperty("force", wheelHit.force);
     writer.WriteProperty("forwardSlip", wheelHit.forwardSlip);
     writer.WriteProperty("sidewaysSlip", wheelHit.sidewaysSlip);
 }
示例#9
0
 static public int constructor(IntPtr l)
 {
     try {
         UnityEngine.WheelHit o;
         o = new UnityEngine.WheelHit();
         pushValue(l, o);
         return(1);
     }
     catch (Exception e) {
         LuaDLL.luaL_error(l, e.ToString());
         return(0);
     }
 }
示例#10
0
 public static int constructor(IntPtr l)
 {
     try {
         UnityEngine.WheelHit o;
         o=new UnityEngine.WheelHit();
         pushValue(l,o);
         return 1;
     }
     catch(Exception e) {
         LuaDLL.luaL_error(l, e.ToString());
         return 0;
     }
 }
 public static int constructor(IntPtr l)
 {
     try {
         UnityEngine.WheelHit o;
         o=new UnityEngine.WheelHit();
         pushValue(l,true);
         pushValue(l,o);
         return 2;
     }
     catch(Exception e) {
         return error(l,e);
     }
 }
示例#12
0
        /// <summary>
        /// Read the data using the reader.
        /// </summary>
        /// <param name="reader">Reader.</param>
        public override object Read(ISaveGameReader reader)
        {
            UnityEngine.WheelHit wheelHit = new UnityEngine.WheelHit();
            foreach (string property in reader.Properties)
            {
                switch (property)
                {
                case "collider":
                    if (wheelHit.collider == null)
                    {
                        wheelHit.collider = reader.ReadProperty <UnityEngine.Collider> ();
                    }
                    else
                    {
                        reader.ReadIntoProperty <UnityEngine.Collider> (wheelHit.collider);
                    }
                    break;

                case "point":
                    wheelHit.point = reader.ReadProperty <UnityEngine.Vector3> ();
                    break;

                case "normal":
                    wheelHit.normal = reader.ReadProperty <UnityEngine.Vector3> ();
                    break;

                case "forwardDir":
                    wheelHit.forwardDir = reader.ReadProperty <UnityEngine.Vector3> ();
                    break;

                case "sidewaysDir":
                    wheelHit.sidewaysDir = reader.ReadProperty <UnityEngine.Vector3> ();
                    break;

                case "force":
                    wheelHit.force = reader.ReadProperty <System.Single> ();
                    break;

                case "forwardSlip":
                    wheelHit.forwardSlip = reader.ReadProperty <System.Single> ();
                    break;

                case "sidewaysSlip":
                    wheelHit.sidewaysSlip = reader.ReadProperty <System.Single> ();
                    break;
                }
            }
            return(wheelHit);
        }
示例#13
0
 static void WheelHit_forwardDir(JSVCall vc)
 {
     if (vc.bGet)
     {
         UnityEngine.WheelHit _this = (UnityEngine.WheelHit)vc.csObj;
         var result = _this.forwardDir;
         JSApi.setVector3S((int)JSApi.SetType.Rval, result);
     }
     else
     {
         UnityEngine.Vector3  arg0  = (UnityEngine.Vector3)JSApi.getVector3S((int)JSApi.GetType.Arg);
         UnityEngine.WheelHit _this = (UnityEngine.WheelHit)vc.csObj;
         _this.forwardDir = arg0;
         JSMgr.changeJSObj(vc.jsObjID, _this);
     }
 }
示例#14
0
// fields

// properties
    static void WheelHit_collider(JSVCall vc)
    {
        if (vc.bGet)
        {
            UnityEngine.WheelHit _this = (UnityEngine.WheelHit)vc.csObj;
            var result = _this.collider;
            JSMgr.datax.setObject((int)JSApi.SetType.Rval, result);
        }
        else
        {
            UnityEngine.Collider arg0  = (UnityEngine.Collider)JSMgr.datax.getObject((int)JSApi.GetType.Arg);
            UnityEngine.WheelHit _this = (UnityEngine.WheelHit)vc.csObj;
            _this.collider = arg0;
            JSMgr.changeJSObj(vc.jsObjID, _this);
        }
    }
示例#15
0
 static void WheelHit_sidewaysSlip(JSVCall vc)
 {
     if (vc.bGet)
     {
         UnityEngine.WheelHit _this = (UnityEngine.WheelHit)vc.csObj;
         var result = _this.sidewaysSlip;
         JSApi.setSingle((int)JSApi.SetType.Rval, (System.Single)(result));
     }
     else
     {
         System.Single        arg0  = (System.Single)JSApi.getSingle((int)JSApi.GetType.Arg);
         UnityEngine.WheelHit _this = (UnityEngine.WheelHit)vc.csObj;
         _this.sidewaysSlip = arg0;
         JSMgr.changeJSObj(vc.jsObjID, _this);
     }
 }
示例#16
0
    // Update is called once per frame
    void FixedUpdate()
    {
        WheelHit hit = new WheelHit();
        float firstTravel = 1.0f;
        float secondTravel = 1.0f;

        if (firstWheel.GetGroundHit (out hit)) {
            firstTravel = (-firstWheel.transform.InverseTransformPoint(hit.point).y - firstWheel.radius) / firstWheel.suspensionDistance;
        }
        if (secondWheel.GetGroundHit (out hit)) {
            secondTravel = (-secondWheel.transform.InverseTransformPoint(hit.point).y - secondWheel.radius) / secondWheel.suspensionDistance;
        }

        float antiRollForce = (firstTravel - secondTravel) * antiRoll;

        carRigidbody.AddForceAtPosition (-antiRollForce * firstWheel.transform.up, firstWheel.transform.position);
        carRigidbody.AddForceAtPosition (antiRollForce * secondWheel.transform.up, secondWheel.transform.position);

        Debug.DrawRay (firstWheel.transform.position, -antiRollForce * firstWheel.transform.up / antiRoll * 10, Color.yellow);
        Debug.DrawRay (secondWheel.transform.position, antiRollForce * secondWheel.transform.up / antiRoll * 10, Color.yellow);
    }
示例#17
0
 public extern bool GetGroundHit(out WheelHit hit);
 public bool GetGroundHit(out WheelHit hit);
示例#19
0
    //Move wheels based on their suspension
    void UpdateWheelPositions()
    {
        WheelHit contact = new WheelHit();

        if(wheelFL.GetGroundHit(out contact))
        {
            Vector3 temp = wheelFL.transform.position;
            temp.y = (contact.point + (wheelFL.transform.up * wheelFL.radius)).y;
            wheelTransformFL.position = temp;
        }
        if(wheelFR.GetGroundHit(out contact))
        {
          Vector3 temp = wheelFR.transform.position;
          temp.y = (contact.point + (wheelFR.transform.up*wheelFR.radius)).y;
          wheelTransformFR.position = temp;
        }
        if(wheelBL.GetGroundHit(out contact))
        {
          Vector3 temp = wheelBL.transform.position;
          temp.y = (contact.point + (wheelBL.transform.up*wheelBL.radius)).y;
          wheelTransformBL.position = temp;
        }
        if(wheelBR.GetGroundHit(out contact))
        {
          Vector3 temp = wheelBR.transform.position;
          temp.y = (contact.point + (wheelBR.transform.up*wheelBR.radius)).y;
          wheelTransformBR.position = temp;
        }
    }
示例#20
0
 static public int get_forwardSlip(IntPtr l)
 {
     UnityEngine.WheelHit o = (UnityEngine.WheelHit)checkSelf(l);
     pushValue(l, o.forwardSlip);
     return(1);
 }
示例#21
0
 public extern bool GetGroundHit(out WheelHit hit);
示例#22
0
    void Update()
    {
        if(runTimer)
        {
            timer += Time.deltaTime;
        }

        //rotate the wheels based on RPM
        float rotationThisFrame = 360*Time.deltaTime;
        wheelTransformFL.Rotate(0,wheelFL.rpm/rotationThisFrame,0);
        wheelTransformFR.Rotate(0,wheelFR.rpm/rotationThisFrame,0);
        wheelTransformBL.Rotate(0,wheelBL.rpm/rotationThisFrame,0);
        wheelTransformBR.Rotate(0,wheelBR.rpm/rotationThisFrame,0);

        //		if(wheelTransformFL.rotation.y < 10 && wheelTransformFL.rotation.y > -10)
        //		{
        //			Vector3 rot = new Vector3(wheelTransformFL.localEulerAngles.x,Input.GetAxis("Horizontal") * maxTurnAngle - wheelTransformFL.localEulerAngles.y,wheelTransformFL.localEulerAngles.z);
        //			wheelTransformFL.localEulerAngles = rot;
        //			wheelTransformFR.localEulerAngles = rot;
        //		}

        //move wheels based on their suspension.
        WheelHit contact = new WheelHit();
        if(wheelFL.GetGroundHit(out contact))
        {
            wheelTransformFL.position = contact.point + (wheelFL.transform.up*wheelFL.radius);
        }
        if(wheelFR.GetGroundHit(out contact))
        {
            wheelTransformFR.position = contact.point + (wheelFR.transform.up*wheelFR.radius);
        }
        if(wheelBL.GetGroundHit(out contact))
        {
            wheelTransformBL.position = contact.point + (wheelBL.transform.up*wheelBL.radius);
        }
        if(wheelBR.GetGroundHit(out contact))
        {
            wheelTransformBR.position = contact.point + (wheelBR.transform.up*wheelBR.radius);
        }
    }
示例#23
0
 static public int get_normal(IntPtr l)
 {
     UnityEngine.WheelHit o = (UnityEngine.WheelHit)checkSelf(l);
     pushValue(l, o.normal);
     return(1);
 }
示例#24
0
 static public int get_collider(IntPtr l)
 {
     UnityEngine.WheelHit o = (UnityEngine.WheelHit)checkSelf(l);
     pushValue(l, o.collider);
     return(1);
 }
示例#25
0
 static public int get_sidewaysDir(IntPtr l)
 {
     UnityEngine.WheelHit o = (UnityEngine.WheelHit)checkSelf(l);
     pushValue(l, o.sidewaysDir);
     return(1);
 }
 private void ApplyTraction(CarWheel Wheel, float motorSlip, float brakeSlip, float handBrakeInput)
 {
     float slipPeak = Wheel.getForwardPeakSlip();
     float slipMax = Wheel.getForwardMaxSlip();
     var Hit = new WheelHit();
     float slip;
     float motor = Mathf.Abs(motorSlip);
     bool grounded = Wheel.getWheelCollider().GetGroundHit(out Hit);
     if (grounded)
     {
         Quaternion steerRot = Quaternion.AngleAxis(Wheel.getWheelCollider().steerAngle, Wheel.transform.up);
         Vector3 wheelDir = steerRot * Wheel.transform.forward;
         Vector3 pointV = rigidbody.GetPointVelocity(Hit.point);
         if (Hit.collider.attachedRigidbody)
             pointV -= Hit.collider.attachedRigidbody.GetPointVelocity(Hit.point);
         float v = Mathf.Abs(Vector3.Dot(pointV, wheelDir));
         if (v + slipPeak <= motorMax)
         {
             slip = motor - v;
             if (slip < 0)
                 slip = 0;
             else if (autoMotorMax && slip > slipPeak)
                 slip = slipPeak;
         }
         else
         {
             float maxSlip;
             if (tractionV3)
                 maxSlip = Mathf.Lerp(slipPeak, 0, Mathf.InverseLerp(motorMax - slipPeak, maxSpeed, v));
             else
                 maxSlip = slipPeak;
             slip = maxSlip * motor / motorMax;
         }
         if (motorSlip < 0)
             slip = -slip;
     }
     else
         slip = motorSlip;
     if (autoBrakeMax && brakeSlip > slipPeak)
         brakeSlip = slipPeak;
     brakeSlip = Mathf.Max(brakeSlip, handBrakeInput * slipMax);
     if (motorInput == 0.0f)
         brakeSlip += rollingFrictionSlip / brakeForceFactor;
     if (!grounded)
     {
         float omega = Wheel.getWheelCollider().rpm * Mathf.Deg2Rad;
         brakeSlip += omega * omega * 0.0008f / brakeForceFactor;
     }
     Wheel.motorInput = slip;
     Wheel.brakeInput = brakeSlip;
 }
示例#27
0
    void UpdateWheelGraphics(Vector3 relativeVelocity)
    {
        wheelCount = -1;

        foreach(Wheel w in wheels)
        {
            wheelCount++;
            WheelCollider wheel = w.collider;
            WheelHit wh = new WheelHit();
            // First we get the velocity at the point where the wheel meets the ground, if the wheel is touching the ground
            if(wheel.GetGroundHit(out wh))
            {
                ///w.wheelGraphic.localPosition = wheel.transform.up * (wheelRadius + wheel.transform.InverseTransformPoint(wh.point).y);

                if(w.steerWheel){
                    w.wheelGraphic.localPosition =new Vector3(w.wheelGraphic.localPosition.x,
                                              0,
                                              w.wheelGraphic.localPosition.z);
                }else{
                    w.wheelGraphic.localPosition =new Vector3(w.wheelGraphic.localPosition.x,
                                              wheel.transform.localPosition.y,
                                              w.wheelGraphic.localPosition.z);
                }

                w.wheelVelo = rigidbody.GetPointVelocity(wh.point);
                w.groundSpeed = w.wheelGraphic.InverseTransformDirection(w.wheelVelo);

                // Code to handle skidmark drawing. Not covered in the tutorial
                if(skidmarks)
                {
                    if(skidmarkTime[wheelCount] < 0.02f && w.lastSkidmark != -1)
                    {
                        skidmarkTime[wheelCount] += Time.deltaTime;
                    }
                    else
                    {
                        float dt = skidmarkTime[wheelCount] == 0.0f ? Time.deltaTime : skidmarkTime[wheelCount];
                        skidmarkTime[wheelCount] = 0.0f;

                        float handbrakeSkidding = handbrake && w.driveWheel ? w.wheelVelo.magnitude * 0.3f : 0.0f;
                        int skidGroundSpeed = (int)Mathf.Abs(w.groundSpeed.x) - 15;
                        if(skidGroundSpeed > 0 || handbrakeSkidding > 0)
                        {
                            Vector3 staticVel = transform.TransformDirection(skidSmoke.localVelocity) + skidSmoke.worldVelocity;
                            if(w.lastSkidmark != -1)
                            {
                                float emission = UnityEngine.Random.Range(skidSmoke.minEmission, skidSmoke.maxEmission);
                                float lastParticleCount = w.lastEmitTime * emission;
                                float currentParticleCount = Time.time * emission;
                                int noOfParticles = Mathf.CeilToInt(currentParticleCount) - Mathf.CeilToInt(lastParticleCount);
                                int lastParticle = Mathf.CeilToInt(lastParticleCount);

                                for(int i = 0; i <= noOfParticles; i++)
                                {
                                    float particleTime = Mathf.InverseLerp(lastParticleCount, currentParticleCount, lastParticle + i);
                                    skidSmoke.Emit(	Vector3.Lerp(w.lastEmitPosition, wh.point, particleTime) + new Vector3(Random.Range(-0.1f, 0.1f), Random.Range(-0.1f, 0.1f), Random.Range(-0.1f, 0.1f)), staticVel + (w.wheelVelo * 0.05f), Random.Range(skidSmoke.minSize, skidSmoke.maxSize) * Mathf.Clamp(skidGroundSpeed * 0.1f,0.5f,1.0f), Random.Range(skidSmoke.minEnergy, skidSmoke.maxEnergy), Color.white);
                                }
                            }
                            else
                            {
                                skidSmoke.Emit(	wh.point + new Vector3(Random.Range(-0.1f, 0.1f), Random.Range(-0.1f, 0.1f), Random.Range(-0.1f, 0.1f)), staticVel + (w.wheelVelo * 0.05f), Random.Range(skidSmoke.minSize, skidSmoke.maxSize) * Mathf.Clamp(skidGroundSpeed * 0.1f,0.5f,1.0f), Random.Range(skidSmoke.minEnergy, skidSmoke.maxEnergy), Color.white);
                            }

                            w.lastEmitPosition = wh.point;
                            w.lastEmitTime = Time.time;

                            w.lastSkidmark = skidmarks.AddSkidMark(wh.point + rigidbody.velocity * dt, wh.normal, (skidGroundSpeed * 0.1f + handbrakeSkidding) * Mathf.Clamp01(wh.force / wheel.suspensionSpring.spring), w.lastSkidmark);
                            sound.Skid(true, Mathf.Clamp01(skidGroundSpeed * 0.1f));
                        }
                        else
                        {
                            w.lastSkidmark = -1;
                            sound.Skid(false, 0);
                        }
                    }
                }
            }
            else
            {
                // If the wheel is not touching the ground we set the position of the wheel graphics to
                // the wheel's transform position + the range of the suspension.
                w.wheelGraphic.position = wheel.transform.position + (-wheel.transform.up * suspensionRange);
                if(w.steerWheel)
                    w.wheelVelo *= 0.9f;
                else
                    w.wheelVelo *= 0.9f * (1 - throttle);

                if(skidmarks)
                {
                    w.lastSkidmark = -1;
                    sound.Skid(false, 0);
                }
            }
            // If the wheel is a steer wheel we apply two rotations:
            // *Rotation around the Steer Column (visualizes the steer direction)
            // *Rotation that visualizes the speed
            if(w.steerWheel)
            {
                Vector3 ea = w.wheelGraphic.parent.localEulerAngles;
                ea.y = steer * maximumTurn;
                w.wheelGraphic.parent.localEulerAngles = ea;
                w.tireGraphic.Rotate(Vector3.right * (w.groundSpeed.z / wheelRadius) * Time.deltaTime * Mathf.Rad2Deg);
            }
            else if(!handbrake && w.driveWheel)
            {
                // If the wheel is a drive wheel it only gets the rotation that visualizes speed.
                // If we are hand braking we don't rotate it.
                w.tireGraphic.Rotate(Vector3.right * ((w.groundSpeed.z + w.groundSpeed.x) / wheelRadius) * Time.deltaTime * Mathf.Rad2Deg);
            }
        }
    }
示例#28
0
 public bool GetGroundHit(out WheelHit hit);
示例#29
0
 public bool GetGroundHit(out WheelHit hit)
 {
     throw new NotImplementedException("なにこれ");
 }