/// <summary> /// Update the bus axle <paramref name="axleInfo"/> /// with the proper steering defined in <paramref name="actualSteering"/> /// and with the torque needed until the bus reached its max speed. /// <param name="axleInfo"></param> /// <param name="actualSteering"></param> void UpdateAxle(AxleBusInfo axleInfo, float actualSteering) { //Check the steering if (axleInfo.steering) { //Applying the steering to the axle. The lerping grants a smooth transition axleInfo.leftWheel.steerAngle = Mathf.Lerp(axleInfo.leftWheel.steerAngle, actualSteering, Time.fixedDeltaTime * turnSpeed); axleInfo.rightWheel.steerAngle = Mathf.Lerp(axleInfo.rightWheel.steerAngle, actualSteering, Time.fixedDeltaTime * turnSpeed); } //Check the motor if (axleInfo.motor) { currentSpeed = 2 * Mathf.PI * axleInfo.leftWheel.radius * axleInfo.leftWheel.rpm * 60 / 1000; if (currentSpeed < MaxSpeed) { //Applying the motor to the axle axleInfo.leftWheel.motorTorque = MotorTorque; axleInfo.rightWheel.motorTorque = MotorTorque; } else { axleInfo.leftWheel.motorTorque = 0; axleInfo.rightWheel.motorTorque = 0; } } }
/// <summary> /// Update the wheel mesh position/rotation with the /// physics value of the axle. /// </summary> /// <param name="axle"></param> void ApplyLocalPositionToVisuals(AxleBusInfo axle) { Vector3 position; Quaternion rotation; //Applying the new position and rotation to the left wheel axle.leftWheel.GetWorldPose(out position, out rotation); axle.leftWheelMesh.transform.position = position; axle.leftWheelMesh.transform.rotation = rotation; //... and to the right one axle.rightWheel.GetWorldPose(out position, out rotation); axle.rightWheelMesh.transform.position = position; axle.rightWheelMesh.transform.rotation = rotation; }
private void Start() { //Initializing axles if (axleInfos != null) { foreach (AxleBusInfo axleInfo in axleInfos) { if (axleInfo.motor) { MotorAxleInfos = axleInfo; } } } this.GetComponent <Rigidbody>().centerOfMass = CenterOfMass; }