public void Init(VehicleEngine e) { engine = e; rigid = engine.GetComponent <Rigidbody>(); wheel.wheelDampingRate = 0.25f; wheel.suspensionDistance = 0.2f; JointSpring js = new JointSpring(); js.spring = 3f * rigid.mass; js.damper = 2f * rigid.mass; js.targetPosition = 0.3f; wheel.suspensionSpring = js; wheel.center = new Vector3(0f, (1f - wheel.suspensionSpring.targetPosition) * wheel.suspensionDistance, 0f); wheel.forceAppPointDistance = 0.7f; wheel.steerAngle = 0; wheel.brakeTorque = 0; wheel.motorTorque = 0; wheel.ConfigureVehicleSubsteps(1f, 20, 20); }
void OnGUI() { if (GUI.Button(new Rect(50, 50, 100, 30), "Clear Monos")) { MonoBehaviour[] monos = creation_obj.GetComponentsInChildren <MonoBehaviour>(true); foreach (MonoBehaviour mono in monos) { if (mono is CreationMeshLoader) { continue; } if (mono is VCMeshMgr) { continue; } MonoBehaviour.Destroy(mono); } foreach (MonoBehaviour mono in monos) { if (mono is CreationMeshLoader) { continue; } if (mono is VCMeshMgr) { continue; } MonoBehaviour.Destroy(mono); } } if (GUI.Button(new Rect(50, 100, 100, 30), "Init Test")) { VehiclePhysics.VehicleEngine engine = creation_obj.AddComponent <VehiclePhysics.VehicleEngine>(); creation_obj.AddComponent <VehiclePhysics.VehicleDemo>().engine = engine; WheelCollider[] wcs = creation_obj.GetComponentsInChildren <WheelCollider>(); foreach (WheelCollider wc in wcs) { wc.enabled = true; } engine.wheels = new VehiclePhysics.VehicleWheel[wcs.Length]; for (int i = 0; i < engine.wheels.Length; ++i) { engine.wheels[i] = new VehiclePhysics.VehicleWheel(); engine.wheels[i].wheel = wcs[i]; engine.wheels[i].model = wcs[i].transform.parent.GetChild(3); engine.wheels[i].maxMotorTorque = 5000; engine.wheels[i].staticBrakeTorque = 1200; engine.wheels[i].dynamicBrakeTorque = 400; engine.wheels[i].footBrakeTorque = 6000; engine.wheels[i].handBrakeTorque = 10000000; } engine.maxMotorTorque = 24000; engine.maxPower = 3000; engine.realMass = 15000; Transform[] ts = creation_obj.GetComponentsInChildren <Transform>(true); foreach (Transform t in ts) { if (t.gameObject.name == "MCollider") { GameObject.Destroy(t.gameObject); } } creation_obj.GetComponent <Rigidbody>().mass = 15000; creation_obj.GetComponent <Rigidbody>().isKinematic = false; } }