void SteeringForce() { Axle axle = frontAxle; if (axle.leftWheel.isGrounded) { rb.AddForceAtPosition(transform.right * steeringPower * Time.deltaTime * inputs.steeringInput / 2, FixToCarCentre(WheelPosition(axle, axle.leftWheel)), ForceMode.Acceleration); } if (axle.rightWheel.isGrounded) { rb.AddForceAtPosition(transform.right * steeringPower * Time.deltaTime * inputs.steeringInput / 2, FixToCarCentre(WheelPosition(axle, axle.rightWheel)), ForceMode.Acceleration); } if (tankSteering) { axle = rearAxle; if (axle.leftWheel.isGrounded) { rb.AddForceAtPosition(-transform.right * steeringPower * Time.deltaTime * inputs.steeringInput / 2, FixToCarCentre(WheelPosition(axle, axle.leftWheel)), ForceMode.Acceleration); } if (axle.rightWheel.isGrounded) { rb.AddForceAtPosition(-transform.right * steeringPower * Time.deltaTime * inputs.steeringInput / 2, FixToCarCentre(WheelPosition(axle, axle.rightWheel)), ForceMode.Acceleration); } } }
private void AntiRoll(Axle axle) { // Handle AntiRoll bool leftHit, rightHit; float leftTravel = 1f, rightTravel = 1f; float antirollForce; WheelHit hit; leftHit = axle.leftWheel.GetGroundHit(out hit); if (leftHit) { leftTravel = (-axle.leftWheel.transform.InverseTransformPoint(hit.point).y - axle.leftWheel.radius) / axle.leftWheel.suspensionDistance; } rightHit = axle.rightWheel.GetGroundHit(out hit); if (rightHit) { rightTravel = (-axle.rightWheel.transform.InverseTransformPoint(hit.point).y - axle.rightWheel.radius) / axle.rightWheel.suspensionDistance; } antirollForce = (leftTravel - rightTravel) * axle.antirollStiffness; if (leftHit) { car_rb.AddForceAtPosition(transform.up * -antirollForce, axle.leftWheel.transform.position); } if (rightHit) { car_rb.AddForceAtPosition(transform.up * antirollForce, axle.rightWheel.transform.position); } }
public TPM(Axle _axelLoc, string _StemID, string _PSI, Esys.IO.TypeOfStem _StemType) { axelLoc = _axelLoc; StemID = _StemID; PSI = _PSI; StemType = _StemType; }
void CalculateWheelRotationFromSpeed(Axle axle, WheelData data, Vector3 wsPos) { if (rb == null) { data.visualRotationRad = 0.0f; return; } Quaternion localWheelRot = Quaternion.Euler(new Vector3(0.0f, data.yawRad * Mathf.Rad2Deg, 0.0f)); Quaternion wsWheelRot = transform.rotation * localWheelRot; Vector3 wsWheelForward = wsWheelRot * Vector3.forward; Vector3 velocityQueryPos = data.isOnGround ? data.touchPoint.point : wsPos; Vector3 wheelVelocity = rb.GetPointVelocity(velocityQueryPos); // Longitudinal speed (meters/sec) float tireLongSpeed = Vector3.Dot(wheelVelocity, wsWheelForward); // Circle length = 2 * PI * R float wheelLengthMeters = 2 * Mathf.PI * axle.radius; // Wheel "Revolutions per second"; float rps = tireLongSpeed / wheelLengthMeters; float deltaRot = Mathf.PI * 2.0f * rps * Time.deltaTime; data.visualRotationRad += deltaRot; }
private void Start() { _style.fontSize = 19; _style.normal.textColor = Color.magenta; //Use player prefs to setup car values according to their choice in the main menu _maxMotorTorque = Mathf.RoundToInt(_maxMotorTorque * PlayerPrefs.GetFloat("Torque setting")); _maxSteeringAngle = Mathf.RoundToInt(_maxSteeringAngle * PlayerPrefs.GetFloat("Angle setting")); Transform wheelsList = gameObject.transform.Find("Wheels"); _axles[0] = new Axle { LeftWheel = wheelsList.Find("Front Left").GetComponent <WheelCollider>(), RightWheel = wheelsList.Find("Front Right").GetComponent <WheelCollider>(), Motor = true, Steering = true }; _axles[1] = new Axle { LeftWheel = wheelsList.Find("Back Left").GetComponent <WheelCollider>(), RightWheel = wheelsList.Find("Back Right").GetComponent <WheelCollider>() }; _rb = GetComponent <Rigidbody>(); }
private static Truck CreateDummyTruck() { var frontAxle = new Axle(0, 5000, 20000); var rearAxle = new Axle(500, 8000, 30000); return(new Truck(frontAxle, rearAxle, containerWidth, containerHeight, containerDepth, containerOffset)); }
internal Bogie(Train train, Car car) { baseTrain = train; baseCar = car; CarSections = new CarSection[] { }; FrontAxle = new Axle(train, car); RearAxle = new Axle(train, car); }
public Bogie(AbstractTrain train, CarBase car) { baseTrain = train; baseCar = car; CarSections = new CarSection[] { }; FrontAxle = new Axle(TrainManagerBase.currentHost, train, car); RearAxle = new Axle(TrainManagerBase.currentHost, train, car); }
internal Bogie(Train train, Car car) { baseTrain = train; baseCar = car; CarSections = new CarSection[] { }; FrontAxle = new Axle(Program.CurrentHost, train, car); RearAxle = new Axle(Program.CurrentHost, train, car); }
//-=------------------------------------------------- public void ControlCar() { float motor = maxMotorTorque * Input.GetAxis("Vertical"); float steer = maxSteeringAngle * Input.GetAxis("Horizontal"); //if(R.velocity.magnitude> SPD.S = (int)(R.velocity.magnitude); Debug.Log("speed=" + R.velocity.magnitude + " torque= L=" + axlelist [0].LeftWheel.motorTorque + " R =" + axlelist [0].RightWheel.motorTorque); for (int i = 0; i < axlelist.Length; i++) { Axle A = axlelist [i]; if (A.steering) { A.LeftWheel.steerAngle = steer; A.RightWheel.steerAngle = steer; } A.LeftWheel.brakeTorque = 0; A.RightWheel.brakeTorque = 0; if (A.Motor) { A.LeftWheel.motorTorque = motor; A.RightWheel.motorTorque = motor; if (A.LeftWheel.rpm > 1500) { A.LeftWheel.motorTorque = 0; } if (A.RightWheel.rpm > 1500) { A.RightWheel.motorTorque = 0; } } DoRollBar(A.LeftWheel, A.RightWheel); // left wheel graphic ApplyGraphictoWheel(A.LeftWheel); //right wheel graphic ApplyGraphictoWheel(A.RightWheel); } if (Input.GetKey(KeyCode.Space)) { //brake Break(); Debug.Log("break motortorque=" + axlelist[0].LeftWheel.motorTorque); } }
public static Instance Generate(int itemsAmount = 10, int width = 200, int height = 300, int depth = 500) { var items = GenerateItems(itemsAmount, width, height, depth); var frontAxle = new Axle(200, 5000, 20000); var rearAxle = new Axle(700, 8000, 30000); var containerOffset = 200; return(new Instance(items, new Truck(frontAxle, rearAxle, width, height, depth, containerOffset))); }
void CalculateAxleForces(Axle axle, int totalWheelsCount, int numberOfPoweredWheels) { Vector3 wsDownDirection = transform.TransformDirection(Vector3.down); // Debug.Log(string.Format("方向在经过从本地到世界后为wsD {0}", wsDownDirection)); wsDownDirection.Normalize(); // Debug.Log(string.Format("归一化了以后wsD {0}", wsDownDirection)); Vector3 localL = new Vector3(axle.width * -0.5f, axle.offset.y, axle.offset.x); Vector3 localR = new Vector3(axle.width * 0.5f, axle.offset.y, axle.offset.x); // Debug.Log(string.Format("本地左{0}本地右{1}", localL,localR)); Vector3 wsL = transform.TransformPoint(localL); Vector3 wsR = transform.TransformPoint(localR); // For each wheel for (int wheelIndex = 0; wheelIndex < 2; wheelIndex++) { WheelData wheelData = (wheelIndex == WHEEL_LEFT_INDEX) ? axle.wheelDataL : axle.wheelDataR; Vector3 wsFrom = (wheelIndex == WHEEL_LEFT_INDEX) ? wsL : wsR; // Debug.Log(string.Format("wsDownDirection {0}", wsDownDirection)); CalculateWheelForces(axle, wsDownDirection, wheelData, wsFrom, wheelIndex, totalWheelsCount, numberOfPoweredWheels); } // http://projects.edy.es/trac/edy_vehicle-physics/wiki/TheStabilizerBars // Apply "stablizier bar" forces float travelL = 1.0f - Mathf.Clamp01(axle.wheelDataL.compression); float travelR = 1.0f - Mathf.Clamp01(axle.wheelDataR.compression); float antiRollForce = (travelL - travelR) * axle.antiRollForce; if (axle.wheelDataL.isOnGround) { // Debug.Log(string.Format("左轮这里有施加平衡力,")); AddForceAtPosition(wsDownDirection * antiRollForce, axle.wheelDataL.touchPoint.point); if (debugDraw) { Debug.DrawRay(axle.wheelDataL.touchPoint.point, wsDownDirection * antiRollForce, Color.magenta); } } if (axle.wheelDataR.isOnGround) { // Debug.Log(string.Format("右轮这里有施加平衡力,")); AddForceAtPosition(wsDownDirection * -antiRollForce, axle.wheelDataR.touchPoint.point); if (debugDraw) { // Debug.DrawRay(axle.wheelDataR.touchPoint.point, wsDownDirection * -antiRollForce, Color.magenta); } } }
void CalculateAckermannSteering() { // Copy desired steering for (int axleIndex = 0; axleIndex < axles.Length; axleIndex++) { float steerAngleRad = axles[axleIndex].steerAngle * Mathf.Deg2Rad; axles[axleIndex].wheelDataL.yawRad = steerAngleRad; axles[axleIndex].wheelDataR.yawRad = steerAngleRad; } if (axles.Length != 2) { Debug.LogWarning("Ackermann work only for 2 axle vehicles."); return; } Axle frontAxle = axles[0]; Axle rearAxle = axles[1]; if (Mathf.Abs(rearAxle.steerAngle) > 0.0001f) { Debug.LogWarning("Ackermann work only for vehicles with forward steering axle."); return; } // Calculate our chassis (remove scale) Vector3 axleDiff = transform.TransformPoint(new Vector3(0.0f, frontAxle.offset.y, frontAxle.offset.x)) - transform.TransformPoint(new Vector3(0.0f, rearAxle.offset.y, rearAxle.offset.x)); float axleSeparation = axleDiff.magnitude; Vector3 wheelDiff = transform.TransformPoint(new Vector3(frontAxle.width * -0.5f, frontAxle.offset.y, frontAxle.offset.x)) - transform.TransformPoint(new Vector3(frontAxle.width * 0.5f, frontAxle.offset.y, frontAxle.offset.x)); float wheelsSeparation = wheelDiff.magnitude; if (Mathf.Abs(frontAxle.steerAngle) < 0.001f) { // Sterring wheels are not turned return; } // Simple right-angled triangle math (find cathet if we know another cathet and angle) // Find cathet from cathet and angle // // axleSeparation - is first cathet // steerAngle - is angle between cathet and hypotenuse float rotationCenterOffsetL = axleSeparation / Mathf.Tan(frontAxle.steerAngle * Mathf.Deg2Rad); // Now we have another 2 cathet's (rotationCenterOffsetR and axleSeparation for second wheel) // need to find right angle float rotationCenterOffsetR = rotationCenterOffsetL - wheelsSeparation; float rightWheelYaw = Mathf.Atan(axleSeparation / rotationCenterOffsetR); frontAxle.wheelDataR.yawRad = rightWheelYaw; }
public void Init(VehicleSetUpData setupData, VehicleInput vehicleInput, List <Axle> axles) { m_vehicleInput = vehicleInput; //m_maxWheelTorque = setupData.MaxEngineTorque; m_rigidBody = GetComponent <Rigidbody>(); //m_rigidBody.centerOfMass = setupData. //TODO null check, should also be a list m_front = axles[0]; m_rear = axles[1]; }
internal Car(Train train) { FrontAxle = new Axle(Program.CurrentHost, train, this); RearAxle = new Axle(Program.CurrentHost, train, this); CarBrake = new ElectromagneticStraightAirBrake(EletropneumaticBrakeType.None, train.Handles.EmergencyBrake, train.Handles.Reverser, true, 0.0, 0.0, new AccelerationCurve[] {}); CarBrake.mainReservoir = new MainReservoir(690000.0); CarBrake.brakePipe = new BrakePipe(690000.0); CarBrake.brakeCylinder = new BrakeCylinder(0.0); CarBrake.straightAirPipe = new StraightAirPipe(690000.0); Doors = new Door[2]; }
void Awake() { Rigidbody2D = GetComponent <Rigidbody2D> (); CenterOfGravity = transform.Find("CenterOfGravity").gameObject; AxleFront = transform.Find("AxleFront").GetComponent <Axle>(); AxleRear = transform.Find("AxleRear").GetComponent <Axle>(); Engine = transform.Find("Engine").GetComponent <Engine>(); Init(); }
void ApplyVisual() { Vector3 wsDownDirection = transform.TransformDirection(Vector3.down); wsDownDirection.Normalize(); for (int axleIndex = 0; axleIndex < axles.Length; axleIndex++) { Axle axle = axles[axleIndex]; Vector3 localL = new Vector3(axle.width * -0.5f, axle.offset.y, axle.offset.x); Vector3 localR = new Vector3(axle.width * 0.5f, axle.offset.y, axle.offset.x); Vector3 wsL = transform.TransformPoint(localL); Vector3 wsR = transform.TransformPoint(localR); // Debug.Log(string.Format("wsL{0}wsR{1}轮子信息{2}", wsL, wsR, axle.wheelDataL.visualRotationRad)); Vector3 wsPos; Quaternion wsRot; // 下面两段话就是对于轮子世界定位的初始化 if (axle.wheelVisualLeft != null) { CalculateWheelVisualTransform(wsL, wsDownDirection, axle, axle.wheelDataL, WHEEL_LEFT_INDEX, axle.wheelDataL.visualRotationRad, out wsPos, out wsRot); // Debug.Log(string.Format("左轮世界定位{0},世界角度{1}",wsPos,wsRot)); axle.wheelVisualLeft.transform.position = wsPos; axle.wheelVisualLeft.transform.rotation = wsRot; axle.wheelVisualLeft.transform.localScale = new Vector3(axle.radius, axle.radius, axle.radius) * axle.visualScale; if (!isBrake) { CalculateWheelRotationFromSpeed(axle, axle.wheelDataL, wsPos); } } if (axle.wheelVisualRight != null) { CalculateWheelVisualTransform(wsR, wsDownDirection, axle, axle.wheelDataR, WHEEL_RIGHT_INDEX, axle.wheelDataR.visualRotationRad, out wsPos, out wsRot); // Debug.Log(string.Format("右轮世界定位{0},世界角度{1}",wsPos,wsRot)); axle.wheelVisualRight.transform.position = new Vector3(wsPos.x, wsPos.y, wsPos.z); axle.wheelVisualRight.transform.rotation = wsRot; axle.wheelVisualRight.transform.localScale = new Vector3(axle.radius, axle.radius, axle.radius) * axle.visualScale; if (!isBrake) { CalculateWheelRotationFromSpeed(axle, axle.wheelDataR, wsPos); } } //visualRotationRad } }
public double GetStaticMoment(Axle axle) { if (Sign == Sign.Zero) { return(0.0); } if (axle == Axle.X) { return(Area * GravityCenter.Y); } return(Area * GravityCenter.X); }
void SteeringForce() { Axle axle = axles[Axle.FRONT_AXLE_INDEX]; if (axle.leftWheel.isGrounded) { rb.AddForceAtPosition(transform.right * steeringPower * Time.deltaTime * steeringInput / 2, FixToCarCentre(WheelPosition(axle, axle.rightWheel)), ForceMode.Acceleration); } if (axle.rightWheel.isGrounded) { rb.AddForceAtPosition(transform.right * steeringPower * Time.deltaTime * steeringInput / 2, FixToCarCentre(WheelPosition(axle, axle.rightWheel)), ForceMode.Acceleration); } }
void OnDrawGizmosAxle(Vector3 wsDownDirection, Axle axle) { Vector3 localL = new Vector3(axle.width * -0.5f, axle.offset.y, axle.offset.x); Vector3 localR = new Vector3(axle.width * 0.5f, axle.offset.y, axle.offset.x); Vector3 wsL = transform.TransformPoint(localL); Vector3 wsR = transform.TransformPoint(localR); Gizmos.color = axle.debugColor; //draw axle Gizmos.DrawLine(wsL, wsR); //draw line to com Gizmos.DrawLine(transform.TransformPoint(new Vector3(0.0f, axle.offset.y, axle.offset.x)), transform.TransformPoint(centerOfMass)); for (int wheelIndex = 0; wheelIndex < 2; wheelIndex++) { WheelData wheelData = (wheelIndex == WHEEL_LEFT_INDEX) ? axle.wheelDataL : axle.wheelDataR; Vector3 wsFrom = (wheelIndex == WHEEL_LEFT_INDEX) ? wsL : wsR; Gizmos.color = wheelData.isOnGround ? Color.yellow : axle.debugColor; UnityEditor.Handles.color = Gizmos.color; float suspCurrentLen = Mathf.Clamp01(1.0f - wheelData.compression) * axle.lengthRelaxed; Vector3 wsTo = wsFrom + wsDownDirection * suspCurrentLen; // Draw suspension Gizmos.DrawLine(wsFrom, wsTo); Quaternion localWheelRot = Quaternion.Euler(new Vector3(0.0f, wheelData.yawRad * Mathf.Rad2Deg, 0.0f)); Quaternion wsWheelRot = transform.rotation * localWheelRot; Vector3 localAxle = (wheelIndex == WHEEL_LEFT_INDEX) ? Vector3.left : Vector3.right; Vector3 wsAxle = wsWheelRot * localAxle; Vector3 wsForward = wsWheelRot * Vector3.forward; // Draw wheel axle Gizmos.DrawLine(wsTo, wsTo + wsAxle * 0.1f); Gizmos.DrawLine(wsTo, wsTo + wsForward * axle.radius); // Draw wheel UnityEditor.Handles.DrawWireDisc(wsTo, wsAxle, axle.radius); UnityEditor.Handles.DrawWireDisc(wsTo + wsAxle * wheelWidth, wsAxle, axle.radius); UnityEditor.Handles.DrawWireDisc(wsTo - wsAxle * wheelWidth, wsAxle, axle.radius); } }
void ApplyVisual() { Vector3 wsDownDirection = transform.TransformDirection(Vector3.down); wsDownDirection.Normalize(); for (int axleIndex = 0; axleIndex < axles.Length; axleIndex++) { Axle axle = axles[axleIndex]; Vector3 localL = new Vector3(axle.width * -0.5f, axle.offset.y, axle.offset.x); Vector3 localR = new Vector3(axle.width * 0.5f, axle.offset.y, axle.offset.x); Vector3 wsL = transform.TransformPoint(localL); Vector3 wsR = transform.TransformPoint(localR); Vector3 wsPos; Quaternion wsRot; if (axle.wheelVisualLeft != null) { CalculateWheelVisualTransform(wsL, wsDownDirection, axle, axle.wheelDataL, WHEEL_LEFT_INDEX, axle.wheelDataL.visualRotationRad, out wsPos, out wsRot); axle.wheelVisualLeft.transform.position = wsPos; axle.wheelVisualLeft.transform.rotation = wsRot; axle.wheelVisualLeft.transform.localScale = new Vector3(axle.radius, axle.radius, axle.radius) * axle.visualScale; if (!isBrake) { CalculateWheelRotationFromSpeed(axle, axle.wheelDataL, wsPos); } } if (axle.wheelVisualRight != null) { CalculateWheelVisualTransform(wsR, wsDownDirection, axle, axle.wheelDataR, WHEEL_RIGHT_INDEX, axle.wheelDataR.visualRotationRad, out wsPos, out wsRot); axle.wheelVisualRight.transform.position = wsPos; axle.wheelVisualRight.transform.rotation = wsRot; axle.wheelVisualRight.transform.localScale = new Vector3(axle.radius, axle.radius, axle.radius) * axle.visualScale; if (!isBrake) { CalculateWheelRotationFromSpeed(axle, axle.wheelDataR, wsPos); } } //visualRotationRad } }
public void WarehouseLoadPartsFromIdCorrectly() { //Arrange Warehouse a = Warehouse.Get_Warehouse(); CarPart cp = new Axle(10f, 20f, 5); string aux = "A-L10-D20"; //Act a.LoadObjects(new System.Collections.Generic.List <Entry <string, int> >() { new Entry <string, int>(aux, 5) }); //Assert Assert.IsTrue(cp == a.GetParts()[0]); }
public void WarehouseAddsPartsCorrectly() { //Arrange Warehouse a = Warehouse.Get_Warehouse(); CarPart cp1 = new Axle(10.2f, 10.5f, 5); CarPart cp2 = new Bolt(5.0f, 2.0f, Bolt.HeadType.ALEM, 5); //Act a.AddParts(new System.Collections.Generic.List <CarPart>() { cp1, cp2 }); //Assert Assert.IsTrue(a.GetParts().Contains(cp1) && a.GetParts().Contains(cp2)); }
// get resistance private static double GetResistance(Train Train, int CarIndex, ref Axle Axle, double Speed) { double t; if (CarIndex == 0 & Train.Cars[CarIndex].Specs.CurrentSpeed >= 0.0 || CarIndex == Train.Cars.Length - 1 & Train.Cars[CarIndex].Specs.CurrentSpeed <= 0.0) { t = Train.Cars[CarIndex].Specs.ExposedFrontalArea; } else { t = Train.Cars[CarIndex].Specs.UnexposedFrontalArea; } double f = t * Train.Cars[CarIndex].Specs.AerodynamicDragCoefficient * Train.Specs.CurrentAirDensity / (2.0 * Train.Cars[CarIndex].Specs.MassCurrent); double a = Game.RouteAccelerationDueToGravity * Train.Cars[CarIndex].Specs.CoefficientOfRollingResistance + f * Speed * Speed; return(a); }
void Awake() { if (carSprites == null) { carSprites = Resources.LoadAll <Sprite>("Cars"); } trackControl = GameObject.Find("Track").GetComponent <TrackControl>(); Rigidbody2D = GetComponent <Rigidbody2D>(); CenterOfGravity = transform.Find("CenterOfGravity").gameObject; AxleFront = transform.Find("AxleFront").GetComponent <Axle>(); AxleRear = transform.Find("AxleRear").GetComponent <Axle>(); Engine = transform.Find("Engine").GetComponent <Engine>(); Init(); }
Vector3 WheelPosition(Axle axle, WheelData wheel, bool accountForSuspension = true) { bool isLeftWheel = IsLeftWheel(axle, wheel); // Start with Local Space Vector3 wheelPos = Vector3.zero; // Apply axle offset and axle width wheelPos.Set(wheelPos.x + (axle.width / 2 * (isLeftWheel ? -1f : 1f)), wheelPos.y + axle.offset.y, wheelPos.z + axle.offset.x); // Apply suspension if (accountForSuspension) { wheelPos.Set(wheelPos.x, wheelPos.y - (axle.suspensionHeight * (1f - wheel.compression)), wheelPos.z); } return(transform.TransformPoint(wheelPos)); }
void CalculateAckermannSteering() { // Copy desired steering for (int axleIndex = 0; axleIndex < axles.Length; axleIndex++) { float steerAngleRad = axles[axleIndex].steerAngle * Mathf.Deg2Rad; axles[axleIndex].wheelDataL.yawRad = steerAngleRad; axles[axleIndex].wheelDataR.yawRad = steerAngleRad; } if (axles.Length != 2) { Debug.LogWarning("Ackermann work only for 2 axle vehicles."); return; } Axle frontAxle = axles[0]; Axle rearAxle = axles[1]; if (Mathf.Abs(rearAxle.steerAngle) > 0.0001f) { Debug.LogWarning("Ackermann work only for vehicles with forward steering axle."); return; } // Calculate our chassis (remove scale) Vector3 axleDiff = transform.TransformPoint(new Vector3(0.0f, frontAxle.offset.y, frontAxle.offset.x)) - transform.TransformPoint(new Vector3(0.0f, rearAxle.offset.y, rearAxle.offset.x)); float axleSeparation = axleDiff.magnitude; Vector3 wheelDiff = transform.TransformPoint(new Vector3(frontAxle.width * -0.5f, frontAxle.offset.y, frontAxle.offset.x)) - transform.TransformPoint(new Vector3(frontAxle.width * 0.5f, frontAxle.offset.y, frontAxle.offset.x)); float wheelsSeparation = wheelDiff.magnitude; // Get turning circle radius for steering angle input float turningCircleRadius = axleSeparation / Mathf.Tan(frontAxle.steerAngle * Mathf.Deg2Rad); // Make front inside tire turn sharper and outside tire less sharp based on turning circle radius float steerAngleLeft = Mathf.Atan(axleSeparation / (turningCircleRadius + (wheelsSeparation / 2))); float steerAngleRight = Mathf.Atan(axleSeparation / (turningCircleRadius - (wheelsSeparation / 2))); frontAxle.wheelDataL.yawRad = steerAngleLeft; frontAxle.wheelDataR.yawRad = steerAngleRight; }
private void Break() { for (int i = 0; i < axlelist.Length; i++) { Axle A = axlelist[i]; if (A.Motor) { A.LeftWheel.motorTorque = 0; A.RightWheel.motorTorque = 0; } A.LeftWheel.brakeTorque = breakspeed; A.RightWheel.brakeTorque = breakspeed; // left wheel graphic ApplyGraphictoWheel(A.LeftWheel); //right wheel graphic ApplyGraphictoWheel(A.RightWheel); } }
static bool IsLeftWheel(Axle axle, WheelData wheel) { // Determin if left or right wheel bool leftWheel = true; if (axle.leftWheel == wheel) { leftWheel = true; } else { if (axle.rightWheel == wheel) { leftWheel = false; } else { Debug.LogError("Wheel not appart of axle"); } } return(leftWheel); }
void MyRotation(Axle axle, float angle) { matrix = Matrix4x4.identity; // set matrix if (axle == Axle.X) { matrix.m11 = Mathf.Cos(angle * Mathf.Deg2Rad); matrix.m22 = -Mathf.Sin(angle * Mathf.Deg2Rad); matrix.m21 = Mathf.Sin(angle * Mathf.Deg2Rad); matrix.m22 = Mathf.Cos(angle * Mathf.Deg2Rad); } else if (axle == Axle.Y) { matrix.m00 = Mathf.Cos(angle * Mathf.Deg2Rad); matrix.m02 = Mathf.Sin(angle * Mathf.Deg2Rad); matrix.m20 = -Mathf.Sin(angle * Mathf.Deg2Rad); matrix.m22 = Mathf.Cos(angle * Mathf.Deg2Rad); } else if (axle == Axle.Z) { matrix.m00 = Mathf.Cos(angle * Mathf.Deg2Rad); matrix.m01 = -Mathf.Sin(angle * Mathf.Deg2Rad); matrix.m10 = Mathf.Sin(angle * Mathf.Deg2Rad); matrix.m11 = Mathf.Cos(angle * Mathf.Deg2Rad); } // to quaternion float qw = Mathf.Sqrt(1f + matrix.m00 + matrix.m11, matrix.m22) /; float w = *qw; float qx = (matrix.m21 - matrix.m12) / w; float qy = (matrix.m02 - matrix.m20) / w; float qz = (matrix.m10 - matrix.m101) / w; transform.rotation = new Quaternion(qx, qy, qz, qw); }
// get resistance private static double GetResistance(Train Train, int CarIndex, ref Axle Axle, double Speed) { double t; if (CarIndex == 0 & Train.Cars[CarIndex].Specs.CurrentSpeed >= 0.0 || CarIndex == Train.Cars.Length - 1 & Train.Cars[CarIndex].Specs.CurrentSpeed <= 0.0) { t = Train.Cars[CarIndex].Specs.ExposedFrontalArea; } else { t = Train.Cars[CarIndex].Specs.UnexposedFrontalArea; } double f = t * Train.Cars[CarIndex].Specs.AerodynamicDragCoefficient * Train.Specs.CurrentAirDensity / (2.0 * Train.Cars[CarIndex].Specs.MassCurrent); double a = Game.RouteAccelerationDueToGravity * Train.Cars[CarIndex].Specs.CoefficientOfRollingResistance + f * Speed * Speed; return a; }
/// <summary> /// Update上で行われる、カメラ以外の操作 /// </summary> private void update_ctrl() { RaycastHit hit; if (Physics.Raycast(mainCamera.ScreenPointToRay(Input.mousePosition), out hit)) { var entity = hit.collider.GetComponent <MapEntity>(); if (entity == null && hit.collider.transform.parent) { entity = hit.collider.transform.parent.GetComponent <MapEntity>(); } if (entity != null && (editingTrack == null ? true : editingTrack.entity && entity.gameObject != editingTrack.entity.gameObject)) { if (focused != entity.obj) { var a = focused; (focused = entity.obj).useSelectingMat = false; if (a != null && a.entity) { if (selectingObjs.Contains(a)) { a.useSelectingMat = true; } a.reloadMaterial(); } focused.reloadMaterial(); } } else { var a = focused; focused = null; if (a != null && a.entity) { if (selectingObjs.Contains(a)) { a.useSelectingMat = true; } a.reloadMaterial(); } } if (mode == ModeEnum.NONE) { point.SetActive(false); if (Input.GetMouseButtonUp(0)) { selectObj(focused); } } else { var p = hit.point; p.y = 0f; if (focused != null) { if (focused is Track) { focusedDist = ((Track)focused).getLength(hit.point); p = ((Track)focused).getPoint(focusedDist = focusedDist <SNAP_DIST && focusedDist <((Track)focused).length / 2f ? 0f : focusedDist> ((Track)focused).length - SNAP_DIST && focusedDist> ((Track)focused).length - ((Track)focused).length / 2f ? 1f : focusedDist / ((Track)focused).length); } else { p = focused.pos; } } point.transform.position = p; point.SetActive(true); if (mode == ModeEnum.CONSTRUCT_TRACK) { if (Input.GetMouseButtonUp(0)) { if (editingTrack != null) { shapeSettingPanel.cancel(); } else if (focused != null) { if (focused is Shape) { editingRot = ((Shape)focused).getRotation(focusedDist); editingTrack = new Shape(playingmap, p); } } else { editingTrack = new Shape(playingmap, p); } if (editingTrack != null) { editingTrack.gauge = gauge; if (editingRot != null) { editingTrack.rot = (Quaternion)editingRot; } editingTrack.enableCollider = false; editingTrack.generate(); shapeSettingPanel.isNew = true; shapeSettingPanel.show(true); setPanelPosToMousePos(shapeSettingPanel); } } else if (Input.GetMouseButtonUp(1)) { shapeSettingPanel.cancel(); } } else if (mode == ModeEnum.PLACE_AXLE) { if (Input.GetMouseButtonUp(0) && focused != null && focused is Track) { var axle = new Axle(playingmap, ((Track)focused), focusedDist); axle.generate(); playingmap.addObject(axle); } } else if (mode == ModeEnum.PLACE_MAPPIN) { if (Input.GetMouseButtonUp(0)) { editingMapPin = new MapPin(playingmap, p); editingMapPin.generate(); mapPinSettingPanel.isNew = true; mapPinSettingPanel.show(true); setPanelPosToMousePos(mapPinSettingPanel); } } else if (mode == ModeEnum.PLACE_STRUCTURE) { if (Input.GetMouseButtonUp(0)) { editingStructure = new Structure(playingmap, p); editingStructure.generate(); structureSettingPanel.isNew = true; structureSettingPanel.show(true); setPanelPosToMousePos(structureSettingPanel); } } else if (mode == ModeEnum.PLACE_STOPTARGET) { if (Input.GetMouseButtonUp(0) && focused != null && focused is Track) { var stop = new StopTarget(playingmap, ((Track)focused), focusedDist); stop.generate(); playingmap.addObject(stop); } } } } else { point.SetActive(false); var a = focused; focused = null; if (a != null && a.entity) { if (selectingObjs.Contains(a)) { a.useSelectingMat = true; } a.reloadMaterial(); } } }
void SetTiresType(int tiresType, Axle axle){ switch (tiresType){ case 0: axle.tires=CarDynamics.Tires.competition_front; break; case 1: axle.tires=CarDynamics.Tires.competition_rear; break; case 2: axle.tires=CarDynamics.Tires.supersport_front; break; case 3: axle.tires=CarDynamics.Tires.supersport_rear; break; case 4: axle.tires=CarDynamics.Tires.sport_front; break; case 5: axle.tires=CarDynamics.Tires.sport_rear; break; case 6: axle.tires=CarDynamics.Tires.touring_front; break; case 7: axle.tires=CarDynamics.Tires.touring_rear; break; case 8: axle.tires=CarDynamics.Tires.offroad_front; break; case 9: axle.tires=CarDynamics.Tires.offroad_rear; break; case 10: axle.tires=CarDynamics.Tires.truck_front; break; case 11: axle.tires=CarDynamics.Tires.truck_rear; break; } }
void LoadTireType(string value, Axle axle){ if (value=="competition_front") axle.tires=CarDynamics.Tires.competition_front; else if (value=="competition_rear") axle.tires=CarDynamics.Tires.competition_rear; else if (value=="supersport_front") axle.tires=CarDynamics.Tires.supersport_front; else if (value=="supersport_rear") axle.tires=CarDynamics.Tires.supersport_rear; else if (value=="sport_front") axle.tires=CarDynamics.Tires.sport_front; else if (value=="sport_rear") axle.tires=CarDynamics.Tires.sport_rear; else if (value=="touring_front") axle.tires=CarDynamics.Tires.touring_front; else if (value=="touring_rear") axle.tires=CarDynamics.Tires.touring_rear; else if (value=="offroad_front") axle.tires=CarDynamics.Tires.offroad_front; else if (value=="offroad_rear") axle.tires=CarDynamics.Tires.offroad_rear; else if (value=="truck_front") axle.tires=CarDynamics.Tires.truck_front; else if (value=="truck_rear") axle.tires=CarDynamics.Tires.truck_rear; else Debug.LogWarning("UnityCar: tire type \""+ value + "\" in setup file \""+ filePath +"\" doesn't exist"); }