// Use this for initialization void Start() { isDrivable = true; InputHandler.LoadInputs(); RRWheel.ConfigureVehicleSubsteps(5, 25, 25); GetComponent <Rigidbody>().centerOfMass = new Vector3(-1f, -1.6f, 0); StartCoroutine(Eggshot()); if (photonView.IsMine || !FindObjectOfType <SceneInfo>().multiplayer) { FindObjectOfType <CameraControl>().SetNewCar(this.gameObject); } }
void Start() { rigidBody = GetComponent <Rigidbody> (); audioSource = GetComponent <AudioSource> (); // I usually alter the center of mass to make the car more stable. I'ts less likely to flip this way. rigidBody.centerOfMass = new Vector3(GetComponent <Rigidbody>().centerOfMass.x, -1.5f, rigidBody.centerOfMass.z); // Call the function to determine the array of waypoints. This sets up the array of points by finding // transform components inside of a source container. // Needed for better RPM readings for heavy vehciles FrontLeftWheel.ConfigureVehicleSubsteps(5f, 10, 10); GetWaypoints(); }
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 Start() { nearestNode = 0; pid = GetComponent <AiPid>(); aiSettings.SetRandomValues(); GetComponent <Respawn>().onRespawn += aiSettings.SetRandomValues; GetComponent <Respawn>().onRespawn += pid.ResetValues; GetComponent <Respawn>().onRespawn += () => { StartCoroutine(RestartHelper()); }; backWheel.ConfigureVehicleSubsteps(1, 12, 15); frontWheel.ConfigureVehicleSubsteps(1, 12, 15); rigidbody = GetComponent <Rigidbody>(); frontWheel.brakeTorque = 0; backWheel.brakeTorque = 0; SetUpPIDReferences(); }
//TODO ADD ALL THE THINGS!!! public void Init() { DifferentialDrive initInfo = gameObject.GetComponentInParent <DifferentialDrive>(); wheel = gameObject.AddComponent <WheelCollider>(); wheel.mass = initInfo.Mass; wheel.radius = initInfo.Radius; wheel.wheelDampingRate = initInfo.WheelDampintRate; wheel.suspensionDistance = initInfo.SuspensionDistance; wheel.forceAppPointDistance = initInfo.ForceAppPointDistance; JointSpring newJointSpring = new JointSpring(); newJointSpring.spring = initInfo.SuspensionSpring; newJointSpring.damper = initInfo.SuspensionDamper; newJointSpring.targetPosition = initInfo.SuspensionTargetPosition; wheel.suspensionSpring = newJointSpring; WheelFrictionCurve fricForward = new WheelFrictionCurve(); fricForward.extremumSlip = initInfo.FricForwardExtremumSlip; fricForward.extremumValue = initInfo.FricForwardExtremumValue; fricForward.asymptoteSlip = initInfo.FricForwardAsymptoteSlip; fricForward.asymptoteValue = initInfo.FricForwardAsymptoteValue; fricForward.stiffness = initInfo.FricForwardStiffness; wheel.forwardFriction = fricForward; WheelFrictionCurve fricSide = new WheelFrictionCurve(); fricSide.extremumSlip = initInfo.FricSideExtremumSlip; fricSide.extremumValue = initInfo.FricSideExtremumValue; fricSide.asymptoteSlip = initInfo.FricSideAsymptoteSlip; fricSide.asymptoteValue = initInfo.FricSideAsymptoteValue; fricSide.stiffness = initInfo.FricForwardStiffness; wheel.sidewaysFriction = fricSide; maxMotorTorque = initInfo.MaxTorque; Debug.Log("MaxRpm: " + initInfo.MaxRPM); wheel.ConfigureVehicleSubsteps(initInfo.MaxRPM, 2, 2); }
void Start() { rb = GetComponent <Rigidbody> (); if (rb.mass < 1000.0f) { rb.mass = 1000.0f; } rb.interpolation = RigidbodyInterpolation.Interpolate; rb.collisionDetectionMode = CollisionDetectionMode.ContinuousDynamic; if (centerOfMass != null) { rb.centerOfMass = transform.InverseTransformPoint(centerOfMass.position); } else { rb.centerOfMass = Vector3.zero; } if (rightFrontWheelCollider != null && leftFrontWheelCollider != null && rightRearWheelCollider != null && leftRearWheelCollider != null) { WheelCollider ColisoresDasRodas = GetComponentInChildren <WheelCollider>(); ColisoresDasRodas.ConfigureVehicleSubsteps(1000.0f, 20, 20); } }
void AddWheel(Transform wheel) { GameObject go = new GameObject("Collider for " + wheel.name); go.transform.SetParent(wheelColliderHolder.transform); WheelCollider wheelCollider = go.AddComponent <WheelCollider>(); wheelCollider.mass = 30f; wheelCollider.suspensionDistance = 0.3f; wheelCollider.forceAppPointDistance = 0.2f; wheelCollider.suspensionSpring = new JointSpring { spring = 35000f, damper = 8000, targetPosition = 0.5f }; wheelCollider.forwardFriction = new WheelFrictionCurve { extremumSlip = 0.4f, extremumValue = 1f, asymptoteSlip = 0.8f, asymptoteValue = 0.5f, stiffness = 1.2f }; wheelCollider.sidewaysFriction = new WheelFrictionCurve { extremumSlip = 0.2f, extremumValue = 1f, asymptoteSlip = 1.5f, asymptoteValue = 1f, stiffness = 2.2f }; go.transform.position = wheel.position; wheelCollider.center = new Vector3(0f, go.transform.localPosition.y / 2, 0f); wheelCollider.radius = wheel.GetComponent <MeshFilter>().mesh.bounds.extents.z; wheelCollider.ConfigureVehicleSubsteps(5.0f, 30, 10); wheelCollider.wheelDampingRate = wheelDampingRate; var data = new WheelData() { transform = wheel, collider = wheelCollider, origPos = wheelColliderHolder.transform.InverseTransformPoint(wheel.position), steering = wheel.name.Contains("Front") }; wheels.Add(data); DistributeTransform(wheel); }
void Start() { wheel = GetComponent <WheelCollider>(); wheel.ConfigureVehicleSubsteps(Const.Wheel.criticalSpeed, Const.Wheel.stepsBelow, Const.Wheel.stepsAbove); wheel.mass = Const.Wheel.mass; wheel.radius = Const.Wheel.radius; wheel.wheelDampingRate = Const.Wheel.wheelDampingRate; wheel.suspensionDistance = Const.Wheel.suspensionDistance; wheel.forceAppPointDistance = Const.Wheel.forceAppPointDistance; WheelFrictionCurve fF = new WheelFrictionCurve(); fF.extremumSlip = Const.Wheel.extremumSlip_fF; fF.extremumValue = Const.Wheel.extremumValue_fF; fF.asymptoteSlip = Const.Wheel.asymptoteSlip_fF; fF.asymptoteValue = Const.Wheel.asymptoteValue_fF; fF.stiffness = Const.Wheel.stiffness_fF; wheel.forwardFriction = fF; WheelFrictionCurve sF = new WheelFrictionCurve(); sF.extremumSlip = Const.Wheel.extremumSlip_sF; sF.extremumValue = Const.Wheel.extremumValue_sF; sF.asymptoteSlip = Const.Wheel.asymptoteSlip_sF; sF.asymptoteValue = Const.Wheel.asymptoteValue_sF; sF.stiffness = Const.Wheel.stiffness_sF; wheel.sidewaysFriction = sF; JointSpring sS = new JointSpring(); sS.damper = Const.Wheel.damper; sS.spring = Const.Wheel.spring; sS.targetPosition = Const.Wheel.targetPosition; wheel.suspensionSpring = sS; }
public void ConfigureWheelSubsteps(float speedThreshold, int stepsBelowThreshold, int stepsAboveThreshold) { wheel.ConfigureVehicleSubsteps(speedThreshold, stepsBelowThreshold, stepsAboveThreshold); }
private void CreatePhysicsColliders() { Bounds boundsPhy = new Bounds(transform.position, Vector3.zero); foreach (Renderer renderer in allRenderers) { if (renderer.name.Contains("Main") || renderer.name.Contains("Cab")) // TODO better way, tags? { boundsPhy = renderer.bounds; } if (renderer.name.Contains("Trailer") || renderer.name.Contains("Underside")) { boundsPhy.Encapsulate(renderer.bounds); } } complexBoxCollider = gameObject.AddComponent <BoxCollider>(); complexBoxCollider.size = simpleBoxCollider.size; //new Vector3(boundsPhy.size.x, boundsPhy.size.y * 0.5f, boundsPhy.size.z); // TODO fit better complexBoxCollider.center = new Vector3(simpleBoxCollider.center.x, bounds.size.y / 2 + 0.5f, simpleBoxCollider.center.z); //boundsPhy.center; // wheel colliders if (NPCManager.Instance == null || NPCManager.Instance.wheelColliderPrefab == null) { return; } wheelColliderHolder = Instantiate(NPCManager.Instance.wheelColliderPrefab, Vector3.zero, Quaternion.identity, transform.GetChild(0)); foreach (Transform child in wheelColliderHolder.transform) { if (child.name.Contains("FR")) { origPosWheelFR = wheelFR.localPosition; child.localPosition = wheelFR.localPosition; wheelColliderFR = child.GetComponent <WheelCollider>(); wheelColliderFR.center = new Vector3(0f, child.localPosition.y / 2, 0f); wheelColliderFR.radius = wheelFR.GetComponent <Renderer>().bounds.extents.z; wheelColliderFR.ConfigureVehicleSubsteps(5.0f, 30, 10); wheelColliderFR.wheelDampingRate = wheelDampingRate; } else if (child.name.Contains("FL")) { origPosWheelFL = wheelFL.localPosition; child.localPosition = wheelFL.localPosition; wheelColliderFL = child.GetComponent <WheelCollider>(); wheelColliderFL.center = new Vector3(0f, child.localPosition.y / 2, 0f); wheelColliderFL.radius = wheelFL.GetComponent <Renderer>().bounds.extents.z; wheelColliderFL.ConfigureVehicleSubsteps(5.0f, 30, 10); wheelColliderFL.wheelDampingRate = wheelDampingRate; } else if (child.name.Contains("RL")) { origPosWheelRL = wheelRL.localPosition; child.localPosition = wheelRL.localPosition; wheelColliderRL = child.GetComponent <WheelCollider>(); wheelColliderRL.center = new Vector3(0f, child.localPosition.y / 2, 0f); wheelColliderRL.radius = wheelRL.GetComponent <Renderer>().bounds.extents.z; wheelColliderRL.ConfigureVehicleSubsteps(5.0f, 30, 10); wheelColliderRL.wheelDampingRate = wheelDampingRate; } else if (child.name.Contains("RR")) { origPosWheelRR = wheelRR.localPosition; child.localPosition = wheelRR.localPosition; wheelColliderRR = child.GetComponent <WheelCollider>(); wheelColliderRR.center = new Vector3(0f, child.localPosition.y / 2, 0f); wheelColliderRR.radius = wheelRR.GetComponent <Renderer>().bounds.extents.z; wheelColliderRR.ConfigureVehicleSubsteps(5.0f, 30, 10); wheelColliderRR.wheelDampingRate = wheelDampingRate; } } }
// Init the car script, finding and making all the necessery game objects. public void Init() { // sets Camera to enable toggle between TPP and FPP. tppCam = GameObject.Find("TPP Cam"); // Sets the steeringwheel index. for (int i = 0; i < Input.GetJoystickNames().Length; i++) { if (Input.GetJoystickNames()[i] == "G29 Driving Force Racing Wheel") { steeringWheelIndex = i; } } // Remove logitechsteringSDK if the Logitechsteringwheel is not connected. if (LogitechGSDK.LogiIsConnected(steeringWheelIndex)) { GameObject.Find("FPP Cam").GetComponent <LogitechSteeringWheel>().enabled = false; } // Sets Gamestate. gameState = GameObject.Find("GameState").GetComponent <GameStateScript>(); if (gameState.cameraType == 0) { tppCam.SetActive(false); } // Sets inputScript. inputScript = GetComponent <InputManager>(); inputScript.enabled = true; // activates the input, used to make the menu not error out. // Sets rigidbody rigidbody = GetComponent <Rigidbody>(); rigidbody.centerOfMass = new Vector3(0, 0.139f, 0.1f); // Hard coding to change the center of mass to make the car more stable. // Binds cosmetic objects (used to rotate the wheel and pedals) steeringWheel = GameObject.FindWithTag("SteeringWheel"); acceleratorPad = GameObject.FindWithTag("AccelleratorPad"); breakPad = GameObject.FindWithTag("BreakPad"); clutchPad = GameObject.FindWithTag("ClutchPad"); // Get all the Wheel Colliders for the car wheels = GetComponentsInChildren <WheelCollider>(); for (int i = 0; i < wheels.Length; i++) { WheelCollider thisWheel = wheels[i]; // Changes the frequency of updates. thisWheel.ConfigureVehicleSubsteps(500, 450, 500); // Adds the wheel prefab to the car. if (wheelShape != null) { var ws = Instantiate(wheelShape); ws.transform.parent = thisWheel.transform; } } // Divide wheels into front and rear wheels // Number of front wheels. Used to decide sizes of arrays int numOfFrontWheels = 0; // Loop to determine number of front wheels foreach (WheelCollider wheel in wheels) { if (wheel.transform.localPosition.z > 0) { numOfFrontWheels++; } } frontWheels = new WheelCollider[numOfFrontWheels]; rearWheels = new WheelCollider[wheels.Length - numOfFrontWheels]; // Indexes used to allow multiple tires at each axis (for example two rear right tires and two rear left tires) int currentRearLeftIndex = 0; int currentRearRightIndex = 1; int currentFrontLeftIndex = 0; int currentFrontRightIndex = 1; // Insert front and rear wheels into their respective arrays where left wheels are even numbers and right wheels are odd numbers. foreach (WheelCollider wheel in wheels) { // Checks if position of wheel is infront of local midpoint. if (wheel.transform.localPosition.z < 0) { // Checks if positon of wheel is to the left of local midline. if (wheel.transform.localPosition.x < 0) { // Rear left tire rearWheels[currentRearLeftIndex] = wheel; currentRearLeftIndex += 2; } else { // Rear right tire rearWheels[currentRearRightIndex] = wheel; currentRearRightIndex += 2; } } else { // Checks if positon of wheel is to the right of local midline. if (wheel.transform.localPosition.x < 0) { // Front left tire frontWheels[currentFrontLeftIndex] = wheel; currentFrontLeftIndex += 2; } else { // Front right tire frontWheels[currentFrontRightIndex] = wheel; currentFrontRightIndex += 2; } } } }
private void Start() { fWheelCollider.ConfigureVehicleSubsteps(5, 12, 15); }
void Start() { if (!isBusrider) { ContentManager cm = FindObjectOfType <ContentManager>(); //initialize car data object. specs = new CarData(); //LOAD CAR SPECS TextAsset ass = cm.Cars[0].LoadAsset("specs.json") as TextAsset; specs = specs.ImportData(ass.text); InitializeCar(); // Set game camera target CourseController ctrl = FindObjectOfType <CourseController>(); ctrl.Camera.GetComponent <CarCamera>().car = this.gameObject.transform; // load the default HUD if no car HUD if (!HUDPrefab) { HUDPrefab = ctrl.DefaultHUD; } HUD = Instantiate(HUDPrefab, ctrl.HUDCanvas.transform).GetComponent <HUD>(); //if no turbo then make sure boost is 1 if (!aspirated) { turboSpool = 1; } engineRPM = 800; GetComponent <Rigidbody>().centerOfMass = CenterOfGravity; gear = 1; wheelFR.ConfigureVehicleSubsteps(5, 12, 15); wheelFL.ConfigureVehicleSubsteps(5, 12, 15); wheelRL.ConfigureVehicleSubsteps(5, 12, 15); wheelRR.ConfigureVehicleSubsteps(5, 12, 15); DataController dataController = FindObjectOfType <DataController>(); dirtiness = dataController.GetDirtiness(); isBusrider = dataController.IsBusrider; tirewearlist = new float[4]; //call the FFB start routine FFBStart(); } if (isBusrider) { CourseController ctrl = FindObjectOfType <CourseController>(); HUDPrefab = ctrl.BusriderHUD; HUD = Instantiate(HUDPrefab, ctrl.HUDCanvas.transform).GetComponent <HUD>(); ctrl.Camera.GetComponent <CarCameraBusrider>().car = this.gameObject.transform; ctrl.Camera.GetComponent <CarCamera>().enabled = false; AIBehaviour AI = gameObject.AddComponent <AIBehaviour>(); AI.car = this; AI.courseController = ctrl; CustomInput.IsAI = true; } }
// public GameObject tire; void Awake() { wc = GetComponent <WheelCollider>(); wc.ConfigureVehicleSubsteps(5f, 12, 15); }
// Update is called once per frame void Update() { wc.ConfigureVehicleSubsteps(criticalSpeed, stepsBelow, stepsAbove); }
void Update() { accelTimer += Time.deltaTime; if (accelTimer > 3.0f) { if (abilityToDrive) { //Alters the angle of the car float angle = maxAngle * XCI.GetAxis(XboxAxis.LeftStickX, controller); for (int wheelNum = 0; wheelNum < 4; ++wheelNum) { //Get the wheel colliders WheelCollider wheel = wheels[wheelNum]; bool frontWheel = (wheelNum < 2); //if wheelnum is 0 or 1, it's a front wheel bool frontLeftWheel = (wheelNum == 0); //Left front wheel bool backLeftWheel = (wheelNum == 2); //Left back wheel //Changes speed based on criticals wheel.ConfigureVehicleSubsteps(criticalSpeed, stepsBelow, stepsAbove); //If the player is not boosting if (player.IsBoosting == false) { //Maintain the RPM if (wheel.rpm < idealRPM) { speed = Mathf.Lerp(speed / 10f, speed, wheel.rpm / idealRPM); } else { speed = Mathf.Lerp(speed, 0, (wheel.rpm - idealRPM) / (maxRPM - idealRPM)); } } //Checking if they are boosting, increase torque if (player.IsBoosting == true) { //Boost speed speed = boostSpeed; } else { //Regular speed speed = torque; } //Sharp turn if (XCI.GetAxis(XboxAxis.RightTrigger, controller) == 1) { //Move the back wheels if (!frontWheel) { wheel.steerAngle = -angle * sharpTurn; } else { wheel.steerAngle = 0.0f; } } else { //Move the front wheels if (!frontWheel) { wheel.steerAngle = 0.0f; } else { wheel.steerAngle = angle; } } //If we are holding down the A button, move forward if (XCI.GetButton(XboxButton.A, controller)) { //Set variables wheel.brakeTorque = 0.0f; carRigidbody.drag = 1.0f; carRigidbody.isKinematic = false; aHasBeenPressed = true; player.dustParticleLeft.Play(); player.dustParticleRight.Play(); driving.UnPause(); //Back wheels if (!frontWheel && driveType != DriveType.FrontWheelDrive) { wheel.motorTorque = speed; } //Front wheels if (frontWheel && driveType != DriveType.RearWheelDrive) { wheel.motorTorque = speed; } } else if (XCI.GetButton(XboxButton.B, controller)) { if (aHasBeenPressed == true) { brakeTimer += Time.deltaTime; if (brakeTimer < 1.5f) { if (wheel.isGrounded == true) { //Stop the car moving and resetting values wheel.motorTorque = 0.0f; wheel.brakeTorque = Mathf.Infinity; carRigidbody.drag = dragAmount; carRigidbody.isKinematic = false; player.dustParticleLeft.Stop(); player.dustParticleRight.Stop(); driving.Pause(); } else { player.dustParticleLeft.Stop(); player.dustParticleRight.Stop(); driving.Pause(); } } else { //Use the reverse function aHasBeenPressed = false; } } else { //Set variables wheel.brakeTorque = 0.0f; carRigidbody.drag = 1.0f; carRigidbody.isKinematic = false; player.dustParticleLeft.Play(); player.dustParticleRight.Play(); driving.UnPause(); //Back wheels if (!frontWheel && driveType != DriveType.FrontWheelDrive) { wheel.motorTorque = -speed; } //Front wheels if (frontWheel && driveType != DriveType.RearWheelDrive) { wheel.motorTorque = -speed; } } } else { if (wheel.isGrounded == true) { //Stop the car moving and resetting values wheel.motorTorque = 0.0f; wheel.brakeTorque = Mathf.Infinity; carRigidbody.drag = dragAmount; carRigidbody.isKinematic = false; aHasBeenPressed = false; player.dustParticleLeft.Stop(); player.dustParticleRight.Stop(); driving.Pause(); } else { player.dustParticleLeft.Stop(); player.dustParticleRight.Stop(); driving.Pause(); } } //Create vector and quanternion Quaternion q; Vector3 p; wheel.GetWorldPose(out p, out q); // Assume that the only child of the wheelcollider is the wheel shape. Transform shapeTransform = wheel.transform.GetChild(0); //Alter the transform shapeTransform.position = p; shapeTransform.rotation = q; } } } }
void Start() { leftWheel.ConfigureVehicleSubsteps(5, 12, 15); rightWheel.ConfigureVehicleSubsteps(5, 12, 15); }