Hi. I decided to fight for better game optymalization using the Dots Job system. I want to do the tire grip calculation on paralel job, but i have problem.
If you see the first value on the list is changed but not the rest of all. Here is the full code (concentate on value D because is the clearly example of mine problem with script and job implementaion and IDK why the int called IndexWheel has issue). Please reply to me as fast as possible if you know and you can help me.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UIElements;
using Unity.Jobs;
using UnityEngine.Jobs;
using Unity.Collections;
using Unity.Burst;
using Unity.Mathematics;
using JetBrains.Annotations;
using Unity.VisualScripting;
using System;
using Palmmedia.ReportGenerator.Core.Reporting.Builders;
#if EDITOR
using UnityEditor.ShaderGraph;
//using UnityEngine.InputSystem;
#endif
public class CarControllerGas : MonoBehaviour
{
public string carName;
public ModifyManage MM;
public string Description = "there is no description";
public string CarType;
public string CarSegment;
public string yearsOfCarProduction;
public int NumberOfCarSeats;
public string Car_Handling_category;
public string Car_s_Country;
/*enum driveType
{
FrontWheelDrive,
RearWheelDrive,
AllWheelDrive
}
[SerializeField] driveType drive;*/
[Header("Drivetype")]
public bool FWD;
public bool RWD;
public bool AWD;
/*enum gearBox
{
Automatic,
manualSequentional
}
[SerializeField] gearBox gearchange;*/
[Header("gearboxType")]
public bool Automatic,
manualSequentional;
//public bool AIact;
//public bool Playeract;
public float SFC;
public float AngleDrift;
public Vector3 DriftForceSteer;
public GameObject Car;
public bool InteriorExist;
public bool ItUsingJob;
public bool ActualPowerCompared;
public bool UseFakePowerCalculations;
public float MaxHP;
public float MaxTorqueInNm;
public float TestValue1 = 1;
public float TestValue2 = 0;
public AnimationCurve FakedEngineTqNm;
public bool CanItShiftAutomaticly;
[Range(20, 2000)] public float FrequencySetupFixed;
[Range(10, 1000)] public float FrequencySetup;
public float RAF;
[Header("Engine and engine specyfications")]
public string CarEngineModel;
public bool CarStatsActivate = false;
private float[] powerHP;
private float[] powerNm;
public float totalPower;
public float engineLoad;
public float engineOnlyPower;
public double engineHorsePower;
public float engineRPM;//, TeoryticalEngineOnGarRPM;
public float startRPM = 1000;
public float maxShiftRPM, minShiftRPM;
public float minEngineRPM, maxRPM;
public bool EngineStart;
public bool engineisStarting;
public float RPMReduc;
public float MinRevStartRPM = 2250;
public float REVMulti = 1.5f;
//public bool IsRevTime = true;
[Range(0.05f, 1.75f)] public float lerpTime;
//private float lerpActiveTime;
[Range(50, 100)] public float lerpSmoothTime = 80;
[Range(5f, 75f)] public float FlyWheelMass;
[Range(0.01f, 0.1f)] public float FlyWheelradius;
public float FlyWheelFullMassKG;
public bool engineLerp = false;
public float exaustLoadValue;
public float exaustSpeedEscapeValue;
public float EngineDicaplecment;
public float numberOfCylinders;
[Range(2, 6)] public int NOV;
[Range(1, 3)] public int IntakeVavles;
public float AirSpeedFlow;
public float AirSpeedFlowTeoryticaltoVacum;
private float vavlesSize;
public float BoreSize;
public float StrokeSize;
public float CompresionRadio;
public float CombustionForce;
[Range(1.40f, 3f)] public float rodRadio;
public float engineVacumPower;
public float engineIneriaOfPressure;
public float fuelOctaneValue = 95f;
[Range(1, 6)] public int FuelToAirRatioMixLevel;
[Range(0.25f, 4f)] public float fuelPressureValue;
public float fuelPressureValueTC;
public float fuelMixingValue;
public float FuelPressureSpeed;
public float pistonSpeed;
public float pistonMass;
public float pistonInertia;
public float AmountofFuelUssage;
public float AmountofAirUssage;
public float DicaplecmentPerOneCilynder;
public float SetIntakeCSize;
public float SetExaustCSize;
public float SetExaustPipeSize;
public ParticleSystem[] exhaustParticles;
public float camshaftProfileMM;
public float camshaftOpenDelay;
public float camshaftLenghtMM;
private float FlowScale;
public float springHard;
public float PowerReductionByCatalizatorUse;
public float NaturalAspiredPressure;
public float EngineCrankshaftMass;
public float EngineCrankshaftInertia;
public float EngineBlockMass;
public float engineMass;
public int NumberofExaustPipes;
[Header("Engine Tuning components and modyfications")]
public AnimationCurve TurbineCharacter;
public bool Turbocharger;
public bool It_uses_Vastegate;
[Range(1, 60)] public float Vastegate_Max_PSI_Value;
[Range(2.5f, 10)] public float IntecoolerSizeAdjust;
public bool It_uses_AntiLag;
[Range(0, 1)] public float Minimum_AntiLag_endForce;
private float AntiLag_Value_Fuel;
private float AntiLag_Value_Air;
private float AntiLag_Value_Other;
[Range(0f, 0.5f)] public float AntiLag_Value_Fuel_Set;
[Range(0f, 5f)] public float AntiLag_Value_Air_Set;
[Range(0.0f, 0.5f)] public float AntiLag_Value_Other_Set;
public int numberOfTurbos;
public bool Supercharger;
public float TurbineMass;
public float TurboChargerSize;
public float TurboRPM;
public int NumberOfTurbosBlades;
public float TurboPresure;
public float SuperchargerIntakeSize;
public float SuperchargerPowerConsuption;
public float SuperChargerRMPMultiplier;
public float SuperChargerSize;
public float SuperchargerMass;
public bool TwinScrollSC;
public float SuperchargerRPM;
public float SuperChargerPresure;
public float LagTest;
[Header("Gearbox and drive")]
[Range(0.002f, 2)] public float ShiftDelay = 0.01f;
public bool IsManual;
public bool ItCanStall;
public float CheckSD = 10;
private float CountDelay = 1;
public float AutomaticLaunchRPM = 2250;
public float KPH;
public bool engineDamp;
public float wheelsPowerRPM;
public float wheelsPowerRPMmax;
public float wheelsRPM;
public double wheelsSpeed;
public double wheelsSpeedMax;
[Range(0.0001f, 0.2f)] public float EngineSmoothTime;
[Range(0.1f, 50f)] public float GearSesitivity;
public bool clutch;
public bool GearUp;
public bool GearDown;
public float gearSize = 0;
public float[] gears;
public float reverseGear;
public bool reverse;
public int gearNum = 0;
[Header("Drive Differentials")]
public float[] WheelTorque = new float[4];
[Header("Front Differential")]
[Range(0, 500)] public int FDiffSlipLimit;
[Range(0.5f, 1f)] public float FDiffGearRadioSize;
[Range(0, 100)] public int FPowerLock;
[Range(0, 100)] public int FCoastLock;
[Range(25f, 100f)] public float FMaxDiffSlip;
private float FLRPM;
private float FRRPM;
private float FLPV;
private float FRPV;
public float FrontLeftTorqueValue;
public float FrontRightTorqueValue;
private float FDifferSpeedValue;
public bool FLSD;
public bool FLockingDiff;
public bool FOpen;
public float FLockPower;
public float FLRLFTM;
public float FRRLFTM;
public float FLTP;
public float FRTP;
[Header("Central Differential")]
[Range(0, 500)] public int CDiffSlipLimit;
[Range(0.5f, 1f)] public float CDiffGearRadioSize;
[Range(0, 100)] public int CPowerLock;
[Range(0, 100)] public int CCoastLock;
[Range(25f, 100f)] public float CMaxDiffSlip;
[Range(10f, 90f)] public float FtRPowerTransfer;
public float CentralFrontTorqueValue;
public float CentralRearTorqueValue;
private float CDifferSpeedValue;
public bool CLSD;
public bool CLockingDiff;
public bool COpen;
public float CLockPower;
public float CFLFTM;
public float CRLFTM;
public float CFTP;
public float CRTP;
[Header("Rear Differential")]
[Range(0, 500)] public int RDiffSlipLimit;
[Range(0.5f, 1f)] public float RDiffGearRadioSize;
[Range(0, 100)] public int RPowerLock;
[Range(0, 100)] public int RCoastLock;
[Range(25f, 100f)] public float RMaxDiffSlip;
public float RearLeftTorqueValue;
public float RearRightTorqueValue;
private float RDifferSpeedValue;
public bool RLSD;
public bool RLockingDiff;
public bool ROpen;
public float RLockPower;
public float RLRLFTM;
public float RRRLFTM;
public float RLTP;
public float RRTP;
/*private float LRPM;
private float RRPM;
private float LPV;
private float RPV;*/
//public float TorqueValue;
[Header("Tires")]
public TireParentVariableSet TPS;
public string ParentName;
public float[] tireRadio;
//public float tireRadio;
public float[] wheelsrim;
public float wheelsrimF;
public float wheelsrimR;
public bool FRTIsDifferent;
public float wheelsRadius = 0.37f;
public float RwheelsRadius = 0.37f;
public float[] wheelWidth;
public float wheelWidthF;
public float wheelWidthR;
[Range(1, 5)] public int TireGripClass;
//public wheelColliderFriction WC;
public float tireStifF_Road;
public float tireStifS_Road;
public float tireStifF_Gravel;
public float tireStifS_Gravel;
public float TireSnowReductionA_F;
public float TireSnowReductionA_S;
public float TireSnowReductionG_F;
public float TireSnowReductionG_S;
public float TireRainReductionA_F;
public float TireRainReductionA_S;
public float TireRainReductionG_F;
public float TireRainReductionG_S;
public float SSF;
public float FSF;
public float SnowValue;
public float RainValue;
public float[] tireStifFBase = new float[4];
public float[] tireStifSBase = new float[4];
public float tireGrip;
public float[] tireActiveOfSpeedRadioDeform = new float[4];
//public float sv;
[Range(2.75f, 4.45f)] public float TireHardnesOnFrontWheels;
[Range(2.75f, 4.45f)] public float TireHardnesOnRearWheels;
public float[] SlipRatio = new float[4];
public float[] Slip2Ddim = new float[4];
public AnimationCurve SlipRatioCurveTest;
public AnimationCurve SlipAngleCurveTest;
public AnimationCurve wheelForceFlexCurve;
public AnimationCurve wheelSidewaysValueGrip;
public AnimationCurve wheelForwardValueGrip;
public AnimationCurve CGFCurve;
public AnimationCurve FCGFCurve;
private float cg;
[Header("Tires Job Test")]
public float[] ValueA;
public float[] ValueB;
public float[] ValueC;
public float[] ValueD;
public float[] ValueE;
private NativeArray<float> StiffnesPowerCDS;
private NativeArray<float> StiffnesPowerCDF;
private NativeArray<float> SG;
private NativeArray<float> SS;
private NativeArray<float> FG;
private NativeArray<float> FS;
private NativeArray<float> S2D;
private NativeArray<float> SRJ;
private NativeArray<float> RPMJ;
private NativeArray<float> FlexForce;
private NativeArray<float> FlexForceDone;
private NativeArray<float> FlexForce1;
private NativeArray<float> FlexForce1Done;
private NativeArray<float> SlipRadioJ;
private NativeArray<float> SlipRadioJDone;
private NativeArray<float> SRLValue;
private NativeArray<float> FslipVF;
private NativeArray<float> SslipVF;
private NativeArray<float> WForceVF;
private NativeArray<float> JobtireFtifFBase;
private NativeArray<float> JobtireStifSBase;
private NativeArray<float> DJobCWF;
private NativeArray<float> DJobCGFCV;
private NativeArray<float> DJobCGFCVD;
private NativeArray<float> DJobFCGFCV;
private NativeArray<float> DJobFCGFCVD;
private NativeArray<float> JSR;
private NativeArray<float> JSRF;
private NativeArray<float> DSSCVJob;
private NativeArray<float> DSSCVJobFinish;
private NativeArray<float> DFSCVJob;
private NativeArray<float> DFSCVJobFinish;
private NativeArray<float> DSACVJob;
private NativeArray<float> DSACVJobFinish;
private NativeArray<float> DFSACVJob;
private NativeArray<float> DFSACVJobFinish;
private NativeArray<float> DJobwheelWidth;
private NativeArray<float> DJobtireRadio;
private NativeArray<float> DJobTireHardnes;
private NativeArray<float> DJobTranswheelMeshValue;
private NativeArray<float> JobforceAppPointDistanceSet;
public float[] FlexForceCurveDone;
public float[] SRCurveDone;
public float[] TestSum;
[Header("Drive Asist and Savety electronics")]
public bool Burnout;
public bool EnableCounterSteerHelp;
[Range(0f, 250f)] public float CounterSteerHelp;
[Range(1f, 50f)] public float speedStart1;
[Range(50f, 150f)] public float speedEnd1;
public bool EnableAntiOverSteerHelp;
[Range(0f, 150f)] public float OverSteerHelp;
public bool ActivatedCurveOfSteerAsist;
public AnimationCurve CurveOfSteerAsist;
[Range(50f, 150f)] public float speedStart2;
public float speedEnd2;
public bool EnableAntiUnderSteerHelp;
[Range(0f, 150f)] public float UnderSteerHelp;
public float UnderSteerValue;
public bool TSC;
public float TSCPowerReduction;
public AnimationCurve TCCurve;
[Range(1f, 5F)] public float TCLevel;
public float MaxFSlip;
public float MaxSSlip;
public bool ABS;
//public AnimationCurve ABSCurve;
public float[] ABSRV = new float[4];
public float[] BrakesTorque = new float[4];
public float MaxFSlipABS;
public float MaxSSlipABS;
[Range(1, 100)] public float ABSPower;
public bool ESC;
public float MaxSSlipESC = 0.075f;
[Range(1, 100)] public float ESCPower = 80;
[Header("AdtionalOptions")]
public bool SpeedLimitInUse;
public float SpeedLimit;
public bool fourWheelsSteering;
public float RearWheelsSteerValue;
public float RearAckermanSteerValue;
public bool ItGotSteerCurveBehaviour;
public AnimationCurve SteerCurveBehaviour;
public float speedDynamic = 125;
public bool AddtionalHeightRegulationModule;
public bool IsPneumatic;
public bool IsElectronic;
public float SetRideHeightValue;
public float AddSuspensionStreightForUse;
[Header("Suspension")]
public float SpringForceRear;
public float SpringForceFront;
public bool AntiRollBarsInUseFront;
public bool AntiRollBarsInUseRear;
public float FLDS;
public float FRDS;
public float RLDS;
public float RRDS;
public float FrontARBForce;
public float RearARBForce;
JointSpring FLSpring;
JointSpring FRSpring;
JointSpring RLSpring;
JointSpring RRSpring;
[Header("Steerning")]
public float finalTurnAngle = 5;
public float MaxSteerAngle = 45;
public bool customSteeringSystem;
[Range(-100, 100)] public float AntiAckermanOrAckermanValue;
private float aacOrAcValue;
public float radius = 7;
public float wheelsBase;
public float rearTrackSize;
[Header("Brakes")]
public float brakePower;
[Range(-100, 100)] public float BrakeForceDistribution;
public float FrontBrakePower;
public float RearBrakePower;
public float HandbrakePower;
[Header("Other")]
//public float handBrakeFrictionMultiplayer = 2f;
[HideInInspector] private double Obwod;
[HideInInspector] private float FObwod;
[Header("DownForce")]
public float AreoForceValueCar;
public float DragForceValueCar;
public float UpperDragForceValueCar;
public GameObject FrontForce;
public GameObject RearForce;
public GameObject[] OtherForce;
public float RearWidth;
public float RearLenght;
public float FrontWidth;
public float FrontLenght;
public float[] OtherWidth;
public float[] OtherLenght;
public float DownForceValue_Front = 0;
public float DownForceValue_Rear = 0;
public float[] DownForceValue_Other;
public int motorTorque = 0;
public float thrust = 1000f;
private float horizontal, vertical;
public float SteerValue;
/*public int ReactValue;
[Range (0.125f, 2f)]public float ShiftTime;
public float CurrientShiftTime;*/
private float engineLerpValue;
public float CWT;
public float wheelRPM_Reduc;
private float MaxCompresion = 1f;
private float[] SSValue = new float[4];
private float lastCallTime;
public float GasValue;
public float ClutchValue;
public float BrakeValue;
public float timer;
public float GearAutoShifttimer;
private float timeValue = 0.5f;
//public float GearDelaytimeValue = 0.5f;
//public bool GearDisableUntilPass;
public float FwheelCamber;
public float RwheelCamber;
[Header("Component Need")]
private Input_Manager IM;
private Rigidbody rigidbody;
private WheelFrictionCurve[] forwardFriction = new WheelFrictionCurve[4];
private WheelFrictionCurve[] sidewaysFriction = new WheelFrictionCurve[4];
private GameObject wheelColliders, wheelMeshes, WCST;
//public GameObject[] suspensionCenter = new GameObject[4];
public WheelCollider[] wheels = new WheelCollider[4];
public GameObject[] wheelMesh = new GameObject[4];
public GameObject[] TranswheelMesh = new GameObject[4];
public GameObject[] wheelsP = new GameObject[4];
public JointSpring SuspensionSpring;
public ParticleSystem[] BrakeParticle;
public bool CanItUseMaterialTo_Brake;
public bool CanItUseMaterialTo_Light;
public bool CanItUseMaterialTo_Reverse;
public Material LightMat1;
public Material LightMat2;
public Material LightMat3;
public Material LightMat4;
public ParticleSystem[] ReverseLightsParticle;
//public Light[] BrakeLights;
public GameObject[] lightObject;
public GameObject[] ParticleBrakeObject;
public Transform Anchor;
//private GameObject WB;
public bool ActiveHeadlight;
public bool ActiveHeadlightLong;
public bool ActiveASHeadlight;
public GameObject[] headlightObject;
public GameObject[] headlightLongObject;
public GameObject[] antiSmokeheadlightObject;
public int LightCount;
/* public int BLV = 2;
public int BPV = 2;
public int LV = 2;
public int LLV = 2;
public int ASLV = 2;*/
[Header("DEBUG")]
public float[] wheelsPower = new float[4];
public bool UpdatePW;
public bool UpdateTQ;
public float PREVTorque;
public float PREVPower;
public float TengineRPM = 2000;
public bool EnableTCStatsHP;
public bool EnableTCStatsNM;
public bool HPUpdated;
public bool NMUpdated;
public AnimationCurve TRC;
public float[] Sslip = new float[4];
public float[] Fslip = new float[4];
public float[] WForce = new float[4];
public float[] TireHardnesLT = new float[4];
public float[] TireHardnes = new float[4];
public float[] TireStiffnes = new float[4];
public float[] BrakesForceCheck = new float[4];
public float RPMKeys;
public int RPMSetupK;
public float ForceE;
public float ForceA;
public float ForceAR;
public float ForceN;
public float ForceT;
public float ForceS;
public float ForceLV;
public float ForceSLV;
public float ForceC;
public float ForceP;
public float ForcePi;
public float ForceFv;
public float ForceFT;
public float ForceVac;
public float ForceAVac;
public float ForceOD;
public float ForceSC;
public float ForceSR;
private float Time_Delay;
public float LOG;
public float LOGY;
private Vector3 wheelPosition = Vector3.zero;
private Quaternion wheelRotation = Quaternion.identity;
public float TF;
private float TimerX;
void Awake()
{
getObjects();
if (CanItUseMaterialTo_Light)
{
LightMat2.EnableKeyword("_EMISSION");
LightMat3.EnableKeyword("_EMISSION");
}
if (CanItUseMaterialTo_Reverse)
{
LightMat4.EnableKeyword("_EMISSION");
}
if (CanItUseMaterialTo_Brake)
{
LightMat1.EnableKeyword("_EMISSION");
}
StiffnesPowerCDS = new NativeArray<float>(wheels.Length, Allocator.Persistent);
StiffnesPowerCDF = new NativeArray<float>(wheels.Length, Allocator.Persistent);
FlexForce = new NativeArray<float>(wheels.Length, Allocator.Persistent);
FlexForceDone = new NativeArray<float>(wheels.Length, Allocator.Persistent);
FlexForce1 = new NativeArray<float>(wheels.Length, Allocator.Persistent);
FlexForce1Done = new NativeArray<float>(wheels.Length, Allocator.Persistent);
SlipRadioJ = new NativeArray<float>(wheels.Length, Allocator.Persistent);
SlipRadioJDone = new NativeArray<float>(wheels.Length, Allocator.Persistent);
SRLValue = new NativeArray<float>(wheels.Length, Allocator.Persistent);
FslipVF = new NativeArray<float>(wheels.Length, Allocator.Persistent);
SslipVF = new NativeArray<float>(wheels.Length, Allocator.Persistent);
WForceVF = new NativeArray<float>(wheels.Length, Allocator.Persistent);
JobtireFtifFBase = new NativeArray<float>(wheels.Length, Allocator.Persistent);
JobtireStifSBase = new NativeArray<float>(wheels.Length, Allocator.Persistent);
DJobCWF = new NativeArray<float>(wheels.Length, Allocator.Persistent);
DJobCGFCV = new NativeArray<float>(wheels.Length, Allocator.Persistent);
DJobCGFCVD = new NativeArray<float>(wheels.Length, Allocator.Persistent);
DJobFCGFCV = new NativeArray<float>(wheels.Length, Allocator.Persistent);
DJobFCGFCVD = new NativeArray<float>(wheels.Length, Allocator.Persistent);
DSSCVJob = new NativeArray<float>(wheels.Length, Allocator.Persistent);
DSSCVJobFinish = new NativeArray<float>(wheels.Length, Allocator.Persistent);
DFSCVJob = new NativeArray<float>(wheels.Length, Allocator.Persistent);
DFSCVJobFinish = new NativeArray<float>(wheels.Length, Allocator.Persistent);
DSACVJob = new NativeArray<float>(wheels.Length, Allocator.Persistent);
DSACVJobFinish = new NativeArray<float>(wheels.Length, Allocator.Persistent);
DFSACVJob = new NativeArray<float>(wheels.Length, Allocator.Persistent);
DFSACVJobFinish = new NativeArray<float>(wheels.Length, Allocator.Persistent);
JSR = new NativeArray<float>(wheels.Length, Allocator.Persistent);
JSRF = new NativeArray<float>(wheels.Length, Allocator.Persistent);
DJobwheelWidth = new NativeArray<float>(wheels.Length, Allocator.Persistent);
DJobtireRadio = new NativeArray<float>(wheels.Length, Allocator.Persistent);
DJobTireHardnes = new NativeArray<float>(wheels.Length, Allocator.Persistent);
DJobTranswheelMeshValue = new NativeArray<float>(wheels.Length, Allocator.Persistent);
JobforceAppPointDistanceSet = new NativeArray<float>(wheels.Length, Allocator.Persistent);
SG = new NativeArray<float>(wheels.Length, Allocator.Persistent);
SS = new NativeArray<float>(wheels.Length, Allocator.Persistent);
FG = new NativeArray<float>(wheels.Length, Allocator.Persistent);
FS = new NativeArray<float>(wheels.Length, Allocator.Persistent);
S2D = new NativeArray<float>(wheels.Length, Allocator.Persistent);
SRJ = new NativeArray<float>(wheels.Length, Allocator.Persistent);
RPMJ = new NativeArray<float>(wheels.Length, Allocator.Persistent);
/*
*/
//Player = GameObject.FindGameObjectWithTag("Player");
}
void FixedUpdate()
{
///lastCallTime += Time.deltaTime;
//if (lastCallTime >= 1 / FrequencySetupFixed)
//{
if (UseFakePowerCalculations == false)
{
calculateEngineTacho();
}
FrontDiff();
RearDiff();
CentralDiff();
wheelGrip();
steerVehicle();
lastCallTime = 0;
TF = Mathf.Lerp(TF, engineRPM, Time.deltaTime / 10);
//}
if (ItUsingJob)
{
TireTestJob job1 = new TireTestJob
{
JobStiffnesPowerCDS = StiffnesPowerCDS,
JobStiffnesPowerCDF = StiffnesPowerCDF,
JobFlexForce = FlexForce,
JobFlexForce1 = FlexForce1,
JobFlexForceFinish = FlexForceDone,
JobFlexForce1Finish = FlexForce1Done,
SRLValueJob = SRLValue,
FslipValue = FslipVF,
SslipValue = SslipVF,
WForceValue = WForceVF,
StifBaseF = JobtireFtifFBase,
StifBaseS = JobtireStifSBase,
JobCWF = DJobCWF,
JobCGFCV = DJobCGFCV,
JobCGFCVD = DJobCGFCVD,
JobFCGFCV = DJobFCGFCV,
JobFCGFCVD = DJobFCGFCVD,
JobwheelWidth = DJobwheelWidth,
JobtireRadio = DJobtireRadio,
JobTireHardnes = DJobTireHardnes,
JobTranswheelMeshValue = DJobTranswheelMeshValue,
SSCVJob = DSSCVJob,
SSCVJobFinish = DSSCVJobFinish,
FSCVJob = DFSCVJob,
FSCVJobFinish = DFSCVJobFinish,
SACVJob = DSACVJob,
SACVJobFinish = DSACVJobFinish,
FSACVJob = DFSACVJob,
FSACVJobFinish = DFSACVJobFinish,
JobSidewaysFEA = SG,
JobSidewaysSEA = SS,
JobForwardFEA = FG,
JobForwardSEA = FS,
JobforceAppPointDistance = JobforceAppPointDistanceSet,
JobSlipRadio = JSR,
JobSlipRadioFinish = JSRF,
SlipTD = S2D,
SlipR = SRJ,
JobSetrpm = RPMJ,
JobSSF = SSF,
JobKPH = KPH,
Jobcg = cg
};
JobHandle TireHandle = job1.Schedule(wheels.Length, 64);
TireHandle.Complete();
for (int i = 0; i < wheels.Length; i++)
{
DJobwheelWidth[i] = wheelWidth[i];
DJobtireRadio[i] = tireRadio[i];
DJobTireHardnes[i] = TireHardnes[i];
DJobTranswheelMeshValue[i] = TranswheelMesh[i].transform.localRotation.x;
FslipVF[i] = Fslip[i];
SslipVF[i] = Sslip[i];
WForceVF[i] = WForce[i];
TestSum[i] = StiffnesPowerCDS[i];
DJobCWF[0] = DJobCWF[2] = 1;
DJobCWF[1] = DJobCWF[3] = -1;
FlexForceDone[i] = wheelForceFlexCurve.Evaluate(FlexForce[i]);
FlexForce1Done[i] = wheelForceFlexCurve.Evaluate(FlexForce1[i]); //wheelForceFlexCurve
JSRF[i] = SlipRatioCurveTest.Evaluate(JSR[i]);
JobtireStifSBase[i] = tireStifSBase[i];
JobtireFtifFBase[i] = tireStifFBase[i];
DSSCVJobFinish[i] = wheelSidewaysValueGrip.Evaluate(DSSCVJob[i]);
DFSCVJobFinish[i] = wheelSidewaysValueGrip.Evaluate(DFSCVJob[i]);
DSACVJobFinish[i] = SlipAngleCurveTest.Evaluate(DSACVJob[i]);
DFSACVJobFinish[i] = SlipAngleCurveTest.Evaluate(DFSACVJob[i]);
DJobCGFCVD[i] = CGFCurve.Evaluate(DJobCGFCV[i]);
DJobFCGFCVD[i] = CGFCurve.Evaluate(DJobFCGFCV[i]);
/*
* JobStiffnesPowerCDS
* JobSidewaysFEA
* JobSidewaysSEA
*
* JobStiffnesPowerCDF
* JobForwardFEA
* JobForwardSEA
* */
ValueA[i] = SslipVF[i];
ValueB[i] = DFSCVJobFinish[i];
ValueC[i] = FlexForce1[i];
ValueD[i] = SRJ[i];
ValueE[i] = DJobCWF[i];
sidewaysFriction[i] = wheels[i].sidewaysFriction;
sidewaysFriction[i].stiffness = StiffnesPowerCDS[i];
sidewaysFriction[i].extremumValue = sidewaysFriction[i].asymptoteValue = SG[i];
sidewaysFriction[i].extremumSlip = sidewaysFriction[i].asymptoteSlip = SS[i];
wheels[i].sidewaysFriction = sidewaysFriction[i];
wheels[i].forceAppPointDistance = -JobforceAppPointDistanceSet[i]; //wheels[i].forceAppPointDistance = -(Mathf.Sqrt(tireStifFBase[i] / 2) * Mathf.Clamp(Mathf.Abs(Fslip[i] / (2 + 2 * Mathf.Abs(Sslip[i]))) - Mathf.Abs(Sslip[i] / 5f), 0, 1) * (((Mathf.Pow(tireRadio[i] + wheels[i].radius, 2) / 10)))) * Mathf.Clamp(wheels[i].rpm, 0.5f, 1) + ((Mathf.Sqrt(Mathf.Clamp(tireStifSBase[i], 0, 2)) / 10) * (Mathf.Clamp(Mathf.Abs(Fslip[i] - (Sslip[i] / 2)), 0.0025f, 0.05f) / 2) * ((tireRadio[i] + wheelWidth[i]) / 10)) * Mathf.Clamp(Mathf.Abs(Sslip[i] * (2 + tireRadio[i] * 10)), 0, 0.01f + ((tireRadio[i] + wheelWidth[i]) / 10));
forwardFriction[i] = wheels[i].forwardFriction;
forwardFriction[i].stiffness = StiffnesPowerCDS[i];
forwardFriction[i].extremumValue = forwardFriction[i].asymptoteValue = FG[i];
forwardFriction[i].extremumSlip = forwardFriction[i].asymptoteSlip = FS[i];
wheels[i].forwardFriction = forwardFriction[i];
/*
public NativeArray<float> SSCVJob;
public NativeArray<float> SSCVJobFinish;
public NativeArray<float> FSCVJob;
public NativeArray<float> FSCVJobFinish;
public NativeArray<float> SACVJob;
public NativeArray<float> c;
public NativeArray<float> FSACVJob;
*/
// FlexForceDone[i] = (wheelForceFlexCurve.Evaluate(FlexForce[i]));
//FlexForce1Done[i] = (wheelForceFlexCurve.Evaluate(FlexForce1[i]));
}
}
}
void Update()
{
//{
//if (Time.time - lastCallTime >= 1 / FrequencySetup)
//{
if (UseFakePowerCalculations == true)
{
//calculateEngineTacho();
}
/*MM = Car.GetComponent<ModifyManage>();
if (MM.Counter < MM.TimeLimit)
{
MM.enabled = true;
}*/
getFriction();
if (!It_uses_AntiLag || It_uses_AntiLag && LagTest > Minimum_AntiLag_endForce)
{
AntiLag_Value_Fuel = 0;
AntiLag_Value_Air = 0;
AntiLag_Value_Other = 0;
}
else
{
AntiLag_Value_Fuel = AntiLag_Value_Fuel_Set;
AntiLag_Value_Air = AntiLag_Value_Air_Set;
AntiLag_Value_Other = AntiLag_Value_Air_Set;
}
addDownForce();
Shifter();
RearBrakePower = brakePower * (1 - (BrakeForceDistribution / 100));
FrontBrakePower = brakePower * (1 + (BrakeForceDistribution / 100));
//lastCallTime = 0;
//}
if (TimerX < 25)
{
TimerX += Time.deltaTime;
}
if (TimerX > 15)
{
wheelColliders.transform.Find("FrontLeftWheel").gameObject.GetComponent<AntiStuckSystem>().enabled = true;
wheelColliders.transform.Find("FrontRightWheel").gameObject.GetComponent<AntiStuckSystem>().enabled = true;
wheelColliders.transform.Find("RearLeftWheel").gameObject.GetComponent<AntiStuckSystem>().enabled = true;
wheelColliders.transform.Find("RearRightWheel").gameObject.GetComponent<AntiStuckSystem>().enabled = true;
}
}
public void LateUpdate()
{
animateWheels();
if (Input.GetKeyDown(KeyCode.I))
{
//if (!EngineStart) EngineStart = true;
//if (!engineisStarting && !EngineStart) engineisStarting = true;
if (EngineStart)
{
EngineStart = false;
engineisStarting = false;
}
else
{
//EngineStart = false;
engineisStarting = true;
}
}
if (Input.GetKeyDown(KeyCode.E))
{
GearUp = true;
//CountDelay += 1;
}
else
{
GearUp = false;
}
if (Input.GetKeyDown(KeyCode.Q))
{
GearDown = true;
//CountDelay += 1;
}
else
{
GearDown = false;
}
if (Input.GetKeyDown(KeyCode.Semicolon))
{
if (!ActiveASHeadlight)
{
ActiveASHeadlight = true;
}
else if (ActiveASHeadlight)
{
ActiveASHeadlight = false;
}
}
EngineDicaplecment = ((StrokeSize / 10) * ((3.14f * Mathf.Pow(BoreSize / 10, 2)) / 4) / 1000) * numberOfCylinders;
headlight();
if (CarStatsActivate)
{
TachoStats();
}
}
float velocity = 1.0f;
public void TachoStats()
{
FlowScale = camshaftLenghtMM / camshaftProfileMM;
float ExaustSize = SetExaustCSize / 1000;
float IntakeSize = SetIntakeCSize / 1000;
float DenseBetweenBlades = TurboChargerSize / NumberOfTurbosBlades;
//if()
if (CarStatsActivate)
{
EnableTCStatsNM = true;
UpdateTQ = true;
//NMUpdated = true;
}
if (EnableTCStatsNM || EnableTCStatsHP)
{
if (UpdateTQ && !NMUpdated || UpdatePW && !HPUpdated)
{
DicaplecmentPerOneCilynder = EngineDicaplecment / numberOfCylinders;
ForceAR = ((SetExaustCSize + SetIntakeCSize) / 20);
ForceLV = ((fuelPressureValue * (1 + AntiLag_Value_Other)) / numberOfCylinders * ExaustSize) * TengineRPM;
ForceSLV = ForceLV * (TengineRPM / 1000) / (SetExaustPipeSize / 10) * Mathf.Clamp((SetExaustPipeSize / 10) * (EngineDicaplecment / 1000), 0.01f, 1);
ForceP = (TengineRPM / 1000) * ((StrokeSize / 1) / (100 * (rodRadio / 2)));
ForcePi = ((pistonMass / 1) * numberOfCylinders) * ForceP;
ForceC = (EngineCrankshaftMass / 100) * (ForceC / 20) / (Mathf.Clamp(TengineRPM, 1, 100000000000000000000000000000000000000f) / 1000);
ForceSC = SuperchargerMass * SuperChargerSize * Mathf.Pow(SuperchargerRPM / 1000, (SuperChargerSize + SuperchargerMass / 10) / 10f);
ForceOD = Mathf.Lerp(0, (camshaftLenghtMM / 1000) / ((springHard / 1000) * (Mathf.Clamp(TengineRPM, 1, 100000000000000000000000000000000000000f) / 1000) * (camshaftProfileMM / 100)) * ((camshaftLenghtMM + camshaftProfileMM) / 10), Time.deltaTime * (springHard / 1000) * (Mathf.Clamp(TengineRPM, 1, 100000000000000000000000000000000000000f) / 1000));
ForceVac = ((StrokeSize / 100) * (ForceP) / 1000) * (DicaplecmentPerOneCilynder) * CompresionRadio * numberOfCylinders;
ForceAVac = Mathf.Clamp(ForceAR - (engineVacumPower / 1), 0f, ForceAR);
//ForceA = (((ForceN / 1) + ((ForceT + ((Mathf.Sqrt(IntecoolerSizeAdjust * (3 * IntecoolerSizeAdjust)) * (ForceT) * IntakeSize))) / 2f) + (Mathf.Sqrt(ForceS * 2f))) * (FlowScale) * Mathf.Sqrt(DicaplecmentPerOneCilynder) / Mathf.Sqrt((ForceVac * 1) / ((rodRadio / 3) / 100)) + ForceAVac);
ForceA = (((ForceN / 1) + ((ForceT + AntiLag_Value_Air + ((Mathf.Sqrt(IntecoolerSizeAdjust * (3 * IntecoolerSizeAdjust)) * (ForceT) * IntakeSize))) / 3f) + (Mathf.Sqrt(ForceS * 2f))) * (FlowScale) * Mathf.Sqrt(DicaplecmentPerOneCilynder) / Mathf.Sqrt((ForceVac * 1) / ((rodRadio / 3) / 100)) + ForceAVac);
ForceFT = ((fuelPressureValue) / 10 + ForceA) * (DicaplecmentPerOneCilynder * numberOfCylinders);
ForceFv = (((AmountofFuelUssage + AntiLag_Value_Fuel) / 10) * (fuelOctaneValue / 9) * (fuelPressureValue / 10) + (ForceA / 1));
//AirSpeedFlowTeoryticaltoVacum = Mathf.Clamp(AirSpeedFlow - (engineVacumPower / 1), 0f, AirSpeedFlow);
ForceE = ((numberOfCylinders * (ForceFv * CompresionRadio * (BoreSize / 100) + ((ForceFT) / ((rodRadio / 1) * 100) * Mathf.Clamp(Mathf.Sqrt(TengineRPM / 1000), 1, 100000)) - ForcePi - ForceC) - Mathf.Abs((springHard / 1000) * (((camshaftLenghtMM + (camshaftProfileMM / (1 * camshaftLenghtMM))) / (100))))) - (ForceSC * 10) - Mathf.Pow(((ForceVac /*/ Mathf.Clamp(GasValue, 0.15f, 1)*/) - (ForceAVac * (ForceOD / 10))) * 100 / Mathf.Pow(rodRadio, 2), 2));
if (!Turbocharger || !Supercharger)
{
ForceN = Mathf.Sqrt(((StrokeSize * BoreSize / 100) * IntakeSize * ExaustSize * Mathf.Sqrt(TengineRPM * numberOfCylinders)));
}
else
{
ForceN = 0;
}
if (!Turbocharger)
{
ForceT = 0;
TurboRPM = 0;
}
if (Turbocharger)
{
if (numberOfTurbos <= 0)
{
numberOfTurbos = 1;
}
//TurboPresure = TurboPresure;
ForceN = 0;
//ForceT = (((((TurboChargerSize * 3.14f / 2)) * numberOfTurbos) * DenseBetweenBlades) * (((((ForceLV * 100)) * NumberOfTurbosBlades / numberOfTurbos) / (TurboChargerSize)) / 1) * IntakeSize) - (ForceVac * 10 / TurboChargerSize);
if (!It_uses_Vastegate)
{
ForceT = (((((TurboChargerSize * 3.14f / 2)) * numberOfTurbos) * DenseBetweenBlades) * (((((ForceLV * 100)) * NumberOfTurbosBlades / numberOfTurbos) / (TurboChargerSize))) * IntakeSize) - (ForceVac * 10 / TurboChargerSize);
}
else
{
ForceT = Mathf.Clamp((((((TurboChargerSize * 3.14f / 2)) * numberOfTurbos) * DenseBetweenBlades) * (((((ForceLV * 100)) * NumberOfTurbosBlades / numberOfTurbos) / (TurboChargerSize))) * IntakeSize) - (ForceVac * 10 / TurboChargerSize), 0, Vastegate_Max_PSI_Value);
}
}
else
{
ForceT = 0f;
}
if (Supercharger)
{
ForceSR = TengineRPM * SuperChargerRMPMultiplier;
if (TwinScrollSC)
{
ForceS = (SuperChargerSize / 10) * SuperchargerRPM * IntakeSize * (SuperchargerIntakeSize * 100) * 1.5f;
}
else
{
ForceS = (SuperChargerSize / 10) * SuperchargerRPM * IntakeSize * (SuperchargerIntakeSize * 100);
}
//SuperChargerPresure = SuperChargerPresure;
}
else //if(Turbocharger && Supercharger)
{
ForceS = 0;
ForceSC = 0;
ForceSR = 0;
}
if (EnableTCStatsNM && !NMUpdated)
{
MaxTorqueInNm = ((ForceE) * (StrokeSize / 100) - ((ForcePi + ForceC) / 100) - ((((PowerReductionByCatalizatorUse / 10) * ((exaustLoadValue * exaustSpeedEscapeValue) / 100)) / Mathf.Sqrt(NumberofExaustPipes))));
}
if (EnableTCStatsHP && !HPUpdated)
{
MaxHP = (((ForceE) * (StrokeSize / 100) - ((ForcePi + ForceC) / 100) - ((((PowerReductionByCatalizatorUse / 10) * ((exaustLoadValue * exaustSpeedEscapeValue) / 100)) / Mathf.Sqrt(NumberofExaustPipes))))) * TengineRPM / 9549.3f * 1.36f;
}
UpdateTQ = false;
UpdatePW = false;
}
}
if (!NMUpdated)
{
if (MaxTorqueInNm >= PREVTorque && !UpdateTQ && TengineRPM < maxRPM)
{
PREVTorque = MaxTorqueInNm;
TengineRPM += 100;
UpdateTQ = true;
}
else
{
if (!NMUpdated)
{
MaxTorqueInNm = PREVTorque;
TengineRPM -= 100;
NMUpdated = true;
}
}
}
if (NMUpdated && !EnableTCStatsHP && !UpdatePW)
{
TengineRPM = maxRPM;
EnableTCStatsHP = true;
}
if (!HPUpdated)
{
if (MaxHP >= PREVPower && !UpdatePW)
{
PREVPower = MaxHP;
TengineRPM -= 100;
UpdatePW = true;
}
else
{
if (!HPUpdated)
{
MaxHP = PREVPower;
TengineRPM += 100;
HPUpdated = true;
}
}
}
}
public void CentralDiff()
{
//if (drive != driveType.AllWheelDrive) return;
float FGearSize = gearSize * FDiffGearRadioSize;
float RGearSize = gearSize * RDiffGearRadioSize;
for (int i = 0; i < wheels.Length; i++)
{
WheelTorque[i] = wheels[i].motorTorque;
}
if (AWD)
{
for (int i = 0; i < wheels.Length; i++)
{
//totalPower = totalPower / 2;
CWT = 4;
if (COpen)
{
//totalPower = totalPower / 2;
CFLFTM = ((wheels[0].rpm + wheels[1].rpm) / 2) - ((wheels[2].rpm + wheels[3].rpm) / 2);
CRLFTM = ((wheels[2].rpm + wheels[3].rpm) / 2) - ((wheels[0].rpm + wheels[1].rpm) / 2);
CFTP = Mathf.Sign(CFLFTM);
CRTP = Mathf.Sign(CRLFTM);
FtRPowerTransfer = 50f;
CentralFrontTorqueValue = Mathf.Abs(totalPower / 1000) * -Mathf.Clamp(CFLFTM / 1000, -1, 1);
CentralRearTorqueValue = Mathf.Abs(totalPower / 1000) * -Mathf.Clamp(CRLFTM / 1000, -1, 1);
// wheels[1].motorTorque = (totalPower * 2) + CentralFrontTorqueValue;
// wheels[0].motorTorque = (totalPower * 2) + CentralRearTorqueValue;
}
else if (CLSD)
{
//totalPower = totalPower / 2;
CFLFTM = ((wheels[0].rpm + wheels[1].rpm) / 2) - ((wheels[2].rpm + wheels[3].rpm) / 2);
CRLFTM = ((wheels[2].rpm + wheels[3].rpm) / 2) - ((wheels[0].rpm + wheels[1].rpm) / 2);
CFTP = Mathf.Sign(CFLFTM);
CRTP = Mathf.Sign(CRLFTM);
int CPowerLockV = CPowerLock / 100;
int CCoastLockV = CCoastLock / 100;
if (Mathf.Abs(CFLFTM) > FMaxDiffSlip || Mathf.Abs(CRLFTM) > FMaxDiffSlip)
{
if (GasValue >= 0)
{
CentralFrontTorqueValue = CFTP * (CDiffSlipLimit * CPowerLockV) * CDiffGearRadioSize * GasValue;//* (FtRPowerTransfer / 100);
CentralRearTorqueValue = CRTP * (CDiffSlipLimit * CPowerLockV) * CDiffGearRadioSize * GasValue;//* ((100 - FtRPowerTransfer) / 100);
}
else
{
CentralFrontTorqueValue = CFTP * (CDiffSlipLimit * CCoastLockV) * CDiffGearRadioSize * BrakeValue;
CentralRearTorqueValue = CRTP * (CDiffSlipLimit * CCoastLockV) * CDiffGearRadioSize * BrakeValue;
}
}
else
{
CentralFrontTorqueValue = 0f;
CentralRearTorqueValue = 0f;
}
}
else if (CLockingDiff)
{
//totalPower = totalPower / 2;
CFLFTM = ((wheels[0].rpm + wheels[1].rpm) / 2) - ((wheels[2].rpm + wheels[3].rpm) / 2);
CRLFTM = ((wheels[2].rpm + wheels[3].rpm) / 2) - ((wheels[0].rpm + wheels[1].rpm) / 2);
CFTP = Mathf.Sign(CFLFTM);
CRTP = Mathf.Sign(CRLFTM);
FtRPowerTransfer = 50f;
//if(Mathf.Abs(wheels[i].rpm/2) > 50f)
if (itsGrounded())
{
if (Mathf.Abs(CFLFTM) > 25 || Mathf.Abs(CRLFTM) > 25)
{
CentralFrontTorqueValue = CFTP * ((CLockPower * Mathf.Clamp(Mathf.Abs(CFLFTM / 100), 0, 1) / 2) * (Mathf.Clamp(KPH, 5f, 15f) / 20));
CentralRearTorqueValue = CRTP * ((CLockPower * Mathf.Clamp(Mathf.Abs(CRLFTM / 100), 0, 1) / 2) * (Mathf.Clamp(KPH, 5f, 15f) / 20));
}
else
{
CentralFrontTorqueValue = 0f;
CentralRearTorqueValue = 0f;
}
}
else if (!itsGrounded())
{
CentralFrontTorqueValue = (CLockPower) * (CFTP);
CentralRearTorqueValue = (CLockPower) * (CRTP);
}
}
else
{
wheels[0].motorTorque = wheels[1].motorTorque = 0f;
wheels[2].motorTorque = wheels[3].motorTorque = 0f;
}
}
}
}
public void FrontDiff()
{
if (FWD || AWD)
{
for (int i = 0; i < wheels.Length - 2; i++)
{
{
//totalPower = totalPower;
CWT = 2;
if (FOpen)
{
FLRLFTM = (wheels[0].rpm - wheels[1].rpm);
FRRLFTM = (wheels[1].rpm - wheels[0].rpm);
FLTP = Mathf.Sign(FLRLFTM);
FRTP = Mathf.Sign(FRRLFTM);
FrontLeftTorqueValue = Mathf.Abs(totalPower / 1000) * -Mathf.Clamp(FLRLFTM / 1000, -1, 1);
FrontRightTorqueValue = Mathf.Abs(totalPower / 1000) * -Mathf.Clamp(FRRLFTM / 1000, -1, 1);
}
else if (FLSD)
{
FLRLFTM = wheels[0].rpm - wheels[1].rpm;
FRRLFTM = wheels[1].rpm - wheels[0].rpm;
FLTP = Mathf.Sign(FLRLFTM);
FRTP = Mathf.Sign(FRRLFTM);
int FPowerLockV = FPowerLock / 100;
int FCoastLockV = FPowerLock / 100;
if (Mathf.Abs(FLRLFTM) > FMaxDiffSlip || Mathf.Abs(FRRLFTM) > FMaxDiffSlip)
{
if (GasValue >= 0.5f)
{
FrontLeftTorqueValue = FLTP * (FDiffSlipLimit * FPowerLockV) * FDiffGearRadioSize;
FrontRightTorqueValue = FRTP * (FDiffSlipLimit * FPowerLockV) * FDiffGearRadioSize;
}
else
{
FrontLeftTorqueValue = FLTP * (FDiffSlipLimit * FCoastLockV) * FDiffGearRadioSize;
FrontRightTorqueValue = FRTP * (FDiffSlipLimit * FCoastLockV) * FDiffGearRadioSize;
}
}
else
{
FrontLeftTorqueValue = 0f;
FrontRightTorqueValue = 0f;
}
}
else if (FLockingDiff)
{
FLRLFTM = wheels[0].rpm - wheels[1].rpm;
FRRLFTM = wheels[1].rpm - wheels[0].rpm;
FLTP = Mathf.Sign(FLRLFTM);
FRTP = Mathf.Sign(FRRLFTM);
//if(Mathf.Abs(wheels[i].rpm/2) > 50f)
if (wheels[0].isGrounded && wheels[1].isGrounded)
{
if (Mathf.Abs(FLRLFTM) > 50f || Mathf.Abs(FRRLFTM) > 50f)
{
FrontLeftTorqueValue = (FLockPower / 1) * (FLTP * Mathf.Clamp(Mathf.Abs(FLRLFTM / 50), 0, 1));
FrontRightTorqueValue = (FLockPower / 1) * (FRTP * Mathf.Clamp(Mathf.Abs(RLRLFTM / 50), 0, 1));
}
else
{
FrontLeftTorqueValue = 0f;
FrontRightTorqueValue = 0f;
}
}
else if (!wheels[i].isGrounded)
{
FrontLeftTorqueValue = (FLockPower / 1) * FLTP;
FrontRightTorqueValue = (FLockPower / 1) * FRTP;
}
}
if (AWD)
{
wheels[1].motorTorque = (totalPower * (FtRPowerTransfer / 50)) + FrontLeftTorqueValue - CentralFrontTorqueValue;
wheels[0].motorTorque = (totalPower * (FtRPowerTransfer / 50)) + FrontRightTorqueValue - CentralFrontTorqueValue;
}
else if (FWD)
{
wheels[1].motorTorque = (totalPower) + FrontLeftTorqueValue;
wheels[0].motorTorque = (totalPower) + FrontRightTorqueValue;
}
else
{
wheels[0].motorTorque = wheels[1].motorTorque = 0f;
}
}
}
}
}
public void RearDiff()
{
//if (drive != driveType.RearWheelDrive) return;
if (RWD || AWD)
{
for (int i = 2; i < wheels.Length; i++)
{
CWT = 2;
if (ROpen)
{
RLRLFTM = (wheels[2].rpm - wheels[3].rpm);
RRRLFTM = (wheels[3].rpm - wheels[2].rpm);
RLTP = Mathf.Sign(RLRLFTM);
RRTP = Mathf.Sign(RRRLFTM);
RearLeftTorqueValue = Mathf.Abs(totalPower / 1000) * -Mathf.Clamp(RLRLFTM / 1000, -1, 1);
RearRightTorqueValue = Mathf.Abs(totalPower / 1000) * -Mathf.Clamp(RLRLFTM / 1000, -1, 1);
}
else if (RLSD)
{
RLRLFTM = wheels[2].rpm - wheels[3].rpm;
RRRLFTM = wheels[3].rpm - wheels[2].rpm;
RLTP = Mathf.Sign(RLRLFTM);
RRTP = Mathf.Sign(RRRLFTM);
int RPowerLockV = RPowerLock / 100;
int RCoastLockV = RPowerLock / 100;
if (Mathf.Abs(RLRLFTM) > RMaxDiffSlip || Mathf.Abs(RRRLFTM) > RMaxDiffSlip)
{
if (GasValue >= 0)
{
RearLeftTorqueValue = RLTP * (RDiffSlipLimit * RPowerLockV) * RDiffGearRadioSize * GasValue;
RearRightTorqueValue = RRTP * (RDiffSlipLimit * RPowerLockV) * RDiffGearRadioSize * GasValue;
}
else if (BrakeValue >= 0)
{
RearLeftTorqueValue = RLTP * (RDiffSlipLimit * RCoastLockV) * RDiffGearRadioSize * BrakeValue;
RearRightTorqueValue = RRTP * (RDiffSlipLimit * RCoastLockV) * RDiffGearRadioSize * BrakeValue;
}
}
else
{
RearLeftTorqueValue = 0f;
RearRightTorqueValue = 0f;
}
}
else if (RLockingDiff)
{
RLRLFTM = wheels[2].rpm - wheels[3].rpm;
RRRLFTM = wheels[3].rpm - wheels[2].rpm;
RLTP = Mathf.Sign(RLRLFTM);
RRTP = Mathf.Sign(RRRLFTM);
if (wheels[2].isGrounded && wheels[3].isGrounded)
{
if (Mathf.Abs(RLRLFTM) > 55f || Mathf.Abs(RRRLFTM) > 55f)
{
RearLeftTorqueValue = (RLockPower / 1) * (RLTP * Mathf.Abs(RLRLFTM / 55));
RearRightTorqueValue = (RLockPower / 1) * (RRTP * Mathf.Abs(RLRLFTM / 55));
}
else
{
RearLeftTorqueValue = 0f;
RearRightTorqueValue = 0f;
}
}
else if (!wheels[i].isGrounded)
{
RearLeftTorqueValue = (RLockPower / 1) * RLTP;
RearRightTorqueValue = (RLockPower / 1) * RRTP;
}
}
if (AWD)
{
wheels[3].motorTorque = (totalPower * ((100 - FtRPowerTransfer) / 50)) + RearLeftTorqueValue - CentralRearTorqueValue;
wheels[2].motorTorque = (totalPower * ((100 - FtRPowerTransfer) / 50)) + RearRightTorqueValue - CentralRearTorqueValue;
}
else if (RWD)
{
wheels[3].motorTorque = (totalPower) + RearLeftTorqueValue;
wheels[2].motorTorque = (totalPower) + RearRightTorqueValue;
}
else
{
wheels[2].motorTorque = wheels[3].motorTorque = 0f;
}
}
}
}
private void calculateEngineTacho()
{
lerpEngine();
/*if (Input.GetKeyDown(KeyCode.LeftShift))
{
rigidbody.AddForce(transform.forward * thrust);
}*/
if (engineRPM > maxRPM)
{
setEngineLerp(maxRPM - RPMReduc);
}
wheelRPM();
FlyWheelFullMassKG = FlyWheelMass * (FlyWheelradius * 10);
if (UseFakePowerCalculations == false)
{
float ExaustSize = SetExaustCSize / 1000;
float IntakeSize = SetIntakeCSize / 1000;
FlowScale = camshaftLenghtMM / camshaftProfileMM;
AirSpeedFlow = (SetExaustCSize + SetExaustCSize) / 20;
engineVacumPower = ((StrokeSize / 100) * (pistonSpeed) / 1000) * (DicaplecmentPerOneCilynder) * CompresionRadio * numberOfCylinders;
DicaplecmentPerOneCilynder = EngineDicaplecment / numberOfCylinders;
CombustionForce = ((numberOfCylinders * (fuelMixingValue * CompresionRadio * (BoreSize / 100) + ((fuelPressureValueTC) / ((rodRadio / 1) * 100) * Mathf.Clamp(Mathf.Sqrt(engineRPM / 1000), 1, 100000)) - pistonInertia - EngineCrankshaftInertia) - Mathf.Abs((springHard / 1000) * (((camshaftLenghtMM + (camshaftProfileMM / (1 * camshaftLenghtMM))) / (100))))) - (SuperchargerPowerConsuption * 10) - Mathf.Pow(((engineVacumPower /*/ Mathf.Clamp(GasValue, 0.15f, 1)*/) - (AirSpeedFlowTeoryticaltoVacum * (camshaftOpenDelay / 10))) * 100 / Mathf.Pow(rodRadio, 2), 2));
AmountofAirUssage = (((NaturalAspiredPressure / 1) + ((TurboPresure + AntiLag_Value_Air + ((Mathf.Sqrt(IntecoolerSizeAdjust * (3 * IntecoolerSizeAdjust)) * (TurboPresure) * IntakeSize))) / 2f) + (Mathf.Sqrt(SuperChargerPresure * 2f))) * (FlowScale) * Mathf.Sqrt(DicaplecmentPerOneCilynder) / Mathf.Sqrt((engineVacumPower * 1) / ((rodRadio / 3) / 100)) + AirSpeedFlowTeoryticaltoVacum);
fuelPressureValueTC = (fuelPressureValue / 10 + AmountofAirUssage) * (DicaplecmentPerOneCilynder * numberOfCylinders);
if (!engineLerp)
{
fuelMixingValue = (((AmountofFuelUssage + AntiLag_Value_Fuel) / 10) * (fuelOctaneValue / 9) * (fuelPressureValue / 10) + (AmountofAirUssage / 1));
}
else
{
fuelMixingValue = 0;
}
exaustLoadValue = ((fuelPressureValue * (1 + AntiLag_Value_Other)) / numberOfCylinders * ExaustSize) * engineRPM * Mathf.Clamp(GasValue, 0.25f, 1);
exaustSpeedEscapeValue = exaustLoadValue * (engineRPM / 1000) / (SetExaustPipeSize / 10) * Mathf.Clamp((SetExaustPipeSize / 10) * (EngineDicaplecment / 1000), 0.01f, 1);
pistonInertia = ((pistonMass / 1) * numberOfCylinders) * pistonSpeed;
pistonSpeed = (engineRPM / 1000) * ((StrokeSize / 1) / (100 * (rodRadio / 2)));
EngineCrankshaftInertia = (EngineCrankshaftMass / 100) * (pistonInertia / 20) / (Mathf.Clamp(engineRPM, 1, 100000000000000000000000000000000000000f) / 1000);
float DenseBetweenBlades = TurboChargerSize / NumberOfTurbosBlades;
camshaftOpenDelay = Mathf.Lerp(0, (camshaftLenghtMM / 1000) / ((springHard / 1000) * (Mathf.Clamp(engineRPM, 1, 100000000000000000000000000000000000000f) / 1000) * (camshaftProfileMM / 100)) * ((camshaftLenghtMM + camshaftProfileMM) / 10), Time.deltaTime * (springHard / 1000) * (Mathf.Clamp(engineRPM, 1, 100000000000000000000000000000000000000f) / 1000));
AirSpeedFlowTeoryticaltoVacum = Mathf.Clamp(AirSpeedFlow - (engineVacumPower / 1), 0f, AirSpeedFlow);
//AirSpeedFlowTeoryticaltoVacum = Mathf.Clamp(AirSpeedFlow - (engineVacumPower / 1), 0f, AirSpeedFlow);
if (!Turbocharger || !Supercharger)
{
NaturalAspiredPressure = Mathf.Sqrt(((StrokeSize * BoreSize / 100) * IntakeSize * ExaustSize * Mathf.Sqrt(engineRPM * numberOfCylinders)));
}
else
{
NaturalAspiredPressure = 0;
}
if (!Turbocharger)
{
TurboPresure = 0;
TurboRPM = 0;
}
if (Turbocharger)
{
if (numberOfTurbos <= 0)
{
numberOfTurbos = 1;
}
//TurboPresure = TurboPresure;
NaturalAspiredPressure = 0;
if (!It_uses_Vastegate)
{
TurboPresure = (((((TurboChargerSize * 3.14f / 2)) * numberOfTurbos) * DenseBetweenBlades) * (TurboRPM / 1) * IntakeSize) * Mathf.Clamp(LagTest + (exaustSpeedEscapeValue / 100), 0, 1) - (engineVacumPower * 10 / TurboChargerSize);
}
else
{
TurboPresure = Mathf.Clamp((((((TurboChargerSize * 3.14f / 2)) * numberOfTurbos) * DenseBetweenBlades) * (TurboRPM / 1) * IntakeSize) * Mathf.Clamp(LagTest + (exaustSpeedEscapeValue / 100), 0, 1) - (engineVacumPower * 10 / TurboChargerSize), 0, Vastegate_Max_PSI_Value);
}
TurboRPM = Mathf.Lerp(TurboRPM, (((exaustLoadValue * 100)) * NumberOfTurbosBlades / numberOfTurbos) / (TurboChargerSize), (((Time.deltaTime) / (TurboChargerSize * 100 / DenseBetweenBlades)) / (TurbineMass / 1000)) * Mathf.Clamp(LagTest * 100 * (2 - Mathf.Clamp(exaustLoadValue, 0.15f, 1)), 0.1f, 1));
//LagTest = TurbineCharacter.Evaluate((((exaustLoadValue * exaustSpeedEscapeValue) * (Mathf.Pow(numberOfTurbos * 10, 2))) * (NumberOfTurbosBlades * (DenseBetweenBlades * (3.14f / 2)) )) * (TurboRPM / 1000) / ((TurbineMass * 1000) * Mathf.Pow(TurboChargerSize * 2,2f)));
LagTest = TurbineCharacter.Evaluate((exaustLoadValue * exaustSpeedEscapeValue) / (Mathf.Pow(TurboChargerSize, 2) * 3.14f / 2) * Mathf.Pow(numberOfTurbos, 2) * (((NumberOfTurbosBlades / 4) * DenseBetweenBlades) / (TurbineMass * 2)));
}
else
{
TurboPresure = 0f;
}
if (Supercharger)
{
SuperchargerRPM = engineRPM * SuperChargerRMPMultiplier;
if (TwinScrollSC)
{
SuperChargerPresure = (SuperChargerSize / 10) * SuperchargerRPM * IntakeSize * (SuperchargerIntakeSize * 1000) * 1.5f;
}
else
{
SuperChargerPresure = (SuperChargerSize / 10) * SuperchargerRPM * IntakeSize * (SuperchargerIntakeSize * 1000);
}
//SuperChargerPresure = SuperChargerPresure;
SuperchargerPowerConsuption = SuperchargerMass * SuperChargerSize * Mathf.Pow(SuperchargerRPM / 100, (SuperChargerSize + SuperchargerMass / 10) / 10f);
}
else //if(Turbocharger && Supercharger)
{
SuperChargerPresure = 0;
SuperchargerPowerConsuption = 0;
SuperchargerRPM = 0;
}
}
if (Supercharger)
{
SuperchargerRPM = engineRPM * SuperChargerRMPMultiplier;
}
if (IsManual)
{
if (CanItShiftAutomaticly)
{
if (CheckSD <= ShiftDelay)
{
CheckSD += Time.fixedDeltaTime + ((0.025f * Mathf.Clamp(IM.vertical, 0, 0.725f)) * (ShiftDelay / 5));
//if (CheckSD <= ShiftDelay / 2)
//{
engineDamp = true;
GasValue = 0;
/*}
else
{
engineDamp = true;
GasValue = GasValue;
engineRPM = Mathf.Clamp(engineRPM, startRPM, maxShiftRPM - 500);
}*/
}
else
{
GasValue = GasValue;
CheckSD = 10;
}
}
else
{
if (CheckSD <= ShiftDelay)
{
CheckSD += Time.fixedDeltaTime + ((0.05f * Mathf.Clamp(IM.vertical, 0, 0.725f)) * (ShiftDelay / 5));
engineDamp = true;
GasValue = 0;
}
else if (CheckSD >= ShiftDelay)
{
GasValue = GasValue;
CheckSD = 10;
}
}
}
engineLoad = Mathf.Lerp(engineLoad, GasValue - ((engineRPM - minEngineRPM) / maxRPM), (EngineSmoothTime * 10) * Time.deltaTime);
if (EngineStart && engineRPM < minEngineRPM || !EngineStart)
{
EngineStart = false;
//engineisStarting = false;
engineRPM = Mathf.LerpUnclamped(engineRPM, 0, Time.deltaTime * EngineSmoothTime * 10);
totalPower = 0;
engineOnlyPower = 0;
}
else
{
engineisStarting = false;
}
if (engineisStarting)
{
if (engineRPM < minEngineRPM && !EngineStart)
{
engineRPM = Mathf.LerpUnclamped(engineRPM, MinRevStartRPM * (1 + GasValue), (1 + (1 * GasValue)) * Time.deltaTime);
}
else
{
EngineStart = true;
engineisStarting = false;
}
}
if (EngineStart)
{
//engineisStarting = false;
/*if (Input.GetKeyDown(KeyCode.I))
{
EngineStart = false;
}*/
//if (engineisStarting)
//{
GasValue = GasValue;
vertical = vertical;
/*if (engineRPM < minEngineRPM)
{
engineRPM = Mathf.Lerp(engineRPM + 1, minEngineRPM + 200, Time.deltaTime);
}*/
/*else if (engineRPM <= minEngineRPM)
{
EngineStart = false;
}*/
/*}
else
{
engineRPM = engineRPM;
//engineisStarting = false;
}*/
if (engineRPM > minEngineRPM)
{
//engineisStarting = false;
vertical = vertical;
engineHorsePower = engineOnlyPower * engineRPM / 9549.3 * 1.36;
if (!engineLerp)
{
GasValue = GasValue;
if (UseFakePowerCalculations)
{
engineOnlyPower = FakedEngineTqNm.Evaluate(engineRPM) * GasValue;
}
else
{
engineOnlyPower = ((CombustionForce * GasValue) * (StrokeSize / 100) - ((pistonInertia + EngineCrankshaftInertia) / 100) - ((((PowerReductionByCatalizatorUse / 10) * ((exaustLoadValue * exaustSpeedEscapeValue) / 100)) / Mathf.Sqrt(NumberofExaustPipes))));
}
}
else
{
engineOnlyPower = 0;
}
wheelRPM_Reduc = Mathf.Lerp(wheelRPM_Reduc, wheelsPowerRPM - wheelsRPM, Time.deltaTime * 100);
if (!reverse)
{
if (!engineDamp)
{
if (manualSequentional)
{
if (gearNum == 0)
{
engineRPM = Mathf.Lerp(engineRPM, (startRPM + Mathf.Abs(wheelsRPM) * gearSize * (gears[gearNum])), ((EngineSmoothTime * GearSesitivity / 10) * ((lerpSmoothTime / 10) * Mathf.Clamp(GasValue, 0.5f, 1f))) * Time.deltaTime);
wheelsSpeedMax = (maxRPM - startRPM) / gearSize / (gears[gearNum]) / 60 * Obwod * 3600 / 1000;
}
else
{
engineRPM = Mathf.Lerp(engineRPM, (Mathf.Abs(wheelsRPM) * gearSize * (gears[gearNum])), ((EngineSmoothTime * GearSesitivity / 10) * ((lerpSmoothTime / 10) * Mathf.Clamp(GasValue, 0.5f, 1f))) * Time.deltaTime);
wheelsSpeedMax = (maxRPM) / gearSize / (gears[gearNum]) / 60 * Obwod * 3600 / 1000;
}
}
else if (Automatic)
{
engineRPM = Mathf.Lerp(engineRPM, (startRPM + Mathf.Abs(wheelsRPM) * gearSize * (gears[gearNum])), ((EngineSmoothTime * GearSesitivity / 10) * ((lerpSmoothTime / 10) * Mathf.Clamp(GasValue, 0.5f, 1f))) * Time.deltaTime);
wheelsSpeedMax = (maxRPM - startRPM) / gearSize / (gears[gearNum]) / 60 * Obwod * 3600 / 1000;
}
/*else if(engineRPM >= maxRPM - RPMReduc)
{
engineRPM = engineRPM;
}*/
/*if (Mathf.Abs(wheelsRPM) > wheelsPowerRPM && KPH < wheelsSpeedMax - 10 && itsGrounded() || !itsGrounded() && Mathf.Abs(wheelsRPM) > wheelsPowerRPM)
{
totalPower = 0;
}
else
{*/
totalPower = (engineOnlyPower * (gears[gearNum]) * gearSize / CWT) * (1 - ClutchValue) * TSCPowerReduction;// * Mathf.Clamp(wheelsPowerRPMmax - Mathf.Abs(wheelsRPM *1.0f), 0, 1);
//}
}
if (!engineLerp || !engineDamp || IM.vertical != 0)
{
FLockPower = engineOnlyPower * (gears[gearNum]) * gearSize / 2;
RLockPower = engineOnlyPower * (gears[gearNum]) * gearSize / 2;
CLockPower = engineOnlyPower * (gears[gearNum]) * gearSize / 2;
}
else
{
FLockPower = 0;
RLockPower = 0;
CLockPower = 0;
}
if (gearNum == 0 || Automatic)
{
wheelsSpeedMax = (maxRPM - startRPM) / gearSize / (gears[gearNum]) / 60 * Obwod * 3600 / 1000;
wheelsPowerRPM = (engineRPM - startRPM) / gearSize / (gears[gearNum]);
wheelsPowerRPMmax = (maxRPM - startRPM) / gearSize / (gears[gearNum]);
}
else
{
wheelsSpeedMax = (maxRPM) / gearSize / (gears[gearNum]) / 60 * Obwod * 3600 / 1000;
wheelsPowerRPM = (engineRPM) / gearSize / (gears[gearNum]);
wheelsPowerRPMmax = (maxRPM) / gearSize / (gears[gearNum]);
}
}
else if (reverse)
{
if (gearNum == 0 || Automatic)
{
wheelsPowerRPMmax = (maxRPM - startRPM) / gearSize / (reverseGear);
}
else
{
wheelsPowerRPMmax = (maxRPM) / gearSize / (reverseGear);
}
if (!engineDamp)
{
wheelsSpeedMax = (maxRPM - startRPM) / gearSize / reverseGear / 60 * Obwod * 3600 / 1000;
engineRPM = Mathf.Lerp(engineRPM, (startRPM + Mathf.Abs(wheelsRPM) * gearSize * (reverseGear)), ((EngineSmoothTime * GearSesitivity / 10) * ((lerpSmoothTime / 10) * Mathf.Clamp(GasValue, 0.5f, 1f))) * Time.deltaTime);
}
/*if (Mathf.Abs(wheelsRPM) > wheelsPowerRPM && KPH < wheelsSpeedMax - 10 && itsGrounded() || !itsGrounded() && Mathf.Abs(wheelsRPM) > wheelsPowerRPM)
{
totalPower = 0;
}
else
{*/
totalPower = -((engineOnlyPower * reverseGear) * gearSize / CWT) * (1 - ClutchValue) * TSCPowerReduction;// * Mathf.Clamp(wheelsPowerRPMmax - Mathf.Abs(wheelsRPM * 1.0f), 0, 1);
//}
if (!engineLerp || !engineDamp || IM.vertical != 0)
{
FLockPower = (engineOnlyPower * (reverseGear) * gearSize) / 2;
RLockPower = (engineOnlyPower * (reverseGear) * gearSize) / 2;
CLockPower = (engineOnlyPower * (reverseGear) * gearSize) / 2;
}
else
{
FLockPower = 0;
RLockPower = 0;
CLockPower = 0;
}
wheelsPowerRPM = (engineRPM - startRPM) / gearSize / reverseGear;
}
/*if (engineLerp && engineRPM >= engineLerpValue || engineRPM < startRPM + (MinRevStartRPM * (Mathf.Clamp(GasValue, 0.25f, 0.3f) * REVMulti)) && gearNum == 0)
{
engineDamp = true;
}*/
/*else
{
totalPower = totalPower;
}*/
// if (!reverse && gearchange == gearBox.Automatic || !reverse && gearchange == gearBox.manualSequentional || reverse && gearchange == gearBox.manualSequentional)
//{
if (engineDamp)
{
ClutchValue = Mathf.Lerp(ClutchValue, GasValue, Time.deltaTime * EngineSmoothTime * GearSesitivity);
if (!engineLerp)
{
engineRPM = Mathf.Lerp(engineRPM, startRPM + ((engineOnlyPower / (engineVacumPower + EngineCrankshaftInertia + EngineCrankshaftInertia)) / Mathf.Sqrt(FlyWheelMass / 1000 * Mathf.Sqrt(FlyWheelradius / 1000 * Mathf.Sqrt(engineRPM / 1000)))), (((EngineSmoothTime / 100)) * ((lerpSmoothTime / 1)) * Time.deltaTime) * (engineVacumPower * (10 / Mathf.Clamp(GasValue, 0.25f, 1))) / Mathf.Sqrt(Mathf.Sqrt(FlyWheelMass / 100) * Mathf.Sqrt((FlyWheelradius * 10) * (Mathf.Sqrt(engineRPM / 1000)))));
GasValue = GasValue;
}
else
{
//engineRPM = engineRPM;
engineRPM = Mathf.Lerp(engineRPM, engineLerpValue - RPMReduc / 10, ((lerpSmoothTime / (lerpTime * 10)) * (1 * EngineSmoothTime)) * Time.deltaTime);
GasValue = 0;
}
//engineRPM = Mathf.Lerp(engineRPM, startRPM + (engineOnlyPower / (engineVacumPower / 100) / (Mathf.Sqrt(pistonInertia * EngineCrankshaftInertia) / rodRadio) * ClutchValue), (((EngineSmoothTime / 1) / lerpTime) * ((lerpSmoothTime / 10) / (engineRPM / 1000)) * Mathf.Clamp(GasValue, 0.5f, 1f)) / (engineVacumPower * 10 * Mathf.Clamp(GasValue,0.075f,1)) * (Time.deltaTime / 10) / Mathf.Clamp(ClutchValue, 0.05f, 1));
totalPower = 0;
}
else
{
engineRPM = engineRPM;
ClutchValue = Mathf.LerpUnclamped(ClutchValue, 0, Time.deltaTime * EngineSmoothTime * GearSesitivity * Mathf.Clamp(1000 * GasValue, 0.1f, 1));
}
}
/*else if (engineRPM < minEngineRPM && engineisStarting)
{
engineRPM = 0;
EngineStart = false;
engineisStarting = false;
}*/
}
if (EngineStart)
{
for (int p = 0; p < exhaustParticles.Length; p++)
{
if (!exhaustParticles[p].isPlaying)
{
exhaustParticles[p].Play();
}
var Main = exhaustParticles[p].main;
Main.startLifetime = Main.simulationSpeed + ((exaustLoadValue / 10) / NumberofExaustPipes / ((PowerReductionByCatalizatorUse * 2) / (SetExaustPipeSize / 2)));
Main.startSize = (exaustLoadValue / (100 / (SetExaustPipeSize / 2))) / NumberofExaustPipes / (PowerReductionByCatalizatorUse / (10 * SetExaustPipeSize) * 2);
Main.startDelay = ((SetExaustPipeSize / NumberofExaustPipes) / 100) / exaustLoadValue;
Main.startSpeed = 0.025f + ((exaustLoadValue * SetExaustPipeSize) / (100 / (SetExaustPipeSize / 10))) / NumberofExaustPipes / (PowerReductionByCatalizatorUse) * ((engineRPM / 1000) / 100);
Main.maxParticles = 256;
}
}
else
{
for (int p = 0; p < exhaustParticles.Length; p++)
{
if (!exhaustParticles[p].isStopped)
{
exhaustParticles[p].Stop();
}
}
}
}
void setEngineLerp(float num)
{
engineLerp = true;
engineLerpValue = num;
}
public void lerpEngine()
{
if (engineLerp)
{
engineLerp = engineRPM <= engineLerpValue ? false : true;
//GasValue = 0;
//engineOnlyPower = 0 /*- engineOnlyPower*/ - (engineVacumPower * (StrokeSize / 100)) - ((pistonInertia * EngineCrankshaftInertia) * 1000);
if (!engineDamp)
{
totalPower = -Mathf.Abs(wheelRPM_Reduc * 1000);
if (FWD)
{
wheels[0].brakeTorque = wheels[1].brakeTorque = Mathf.Abs(wheelRPM_Reduc * 1000);
}
else if (RWD)
{
wheels[2].brakeTorque = wheels[3].brakeTorque = Mathf.Abs(wheelRPM_Reduc * 1000);
}
else
{
wheels[0].brakeTorque = wheels[1].brakeTorque = Mathf.Abs(wheelRPM_Reduc * 1000);
wheels[2].brakeTorque = wheels[3].brakeTorque = Mathf.Abs(wheelRPM_Reduc * 1000);
}
}
else
{
totalPower = 0;
}
}
}
private void wheelRPM()
{
//if (!ItUsingJob)
//{
float sum = 0;
int R = 0;
if (AWD)
{
for (int i = 0; i < 4; i++)
{
sum += wheels[i].rpm;
R++;
}
//Obwod = 2 * 3.14 * wheelsRadius;
wheelsRPM = (R != 0) ? sum / R : 0;
}
else if (RWD)
{
wheelsRPM = (wheels[2].rpm + wheels[3].rpm) / 2;
}
else
{
wheelsRPM = (wheels[0].rpm + wheels[1].rpm) / 2;
}
if (!FRTIsDifferent)
{
Obwod = 2 * 3.14 * wheelsRadius;
}
else
{
if (RWD)
{
Obwod = 2 * 3.14 * RwheelsRadius;
}
else
{
Obwod = 2 * 3.14 * wheelsRadius;
}
}
if (gearNum == 0)
{
if (!reverse)
{
wheelsSpeed = ((engineRPM - startRPM) / gearSize / (gears[gearNum])) / 60 * Obwod * 3600 / 1000;
}
else
{
wheelsSpeed = ((engineRPM - startRPM) / gearSize / (reverseGear)) / 60 * Obwod * 3600 / 1000;
}
}
else
{
if (Automatic)
{
wheelsSpeed = ((engineRPM - startRPM) / gearSize / (gears[gearNum])) / 60 * Obwod * 3600 / 1000;
}
else
{
wheelsSpeed = ((engineRPM) / gearSize / (gears[gearNum])) / 60 * Obwod * 3600 / 1000;
}
}
//}
}
public void Shifter()
{
bool wasInvoked;
if (Automatic)
{
/*if (GearAutoShifttimer < GearDelaytimeValue)
{
GearDisableUntilPass = true;
}
else
{
GearDisableUntilPass = false;
}*/
if (!itsGrounded()) return;
if (!itsGotTraction()) return;
if (clutch) return;
if (!reverse && IM.vertical < 0 && gearNum == 0 && KPH <= 1)
{
reverse = true;
}
else if (reverse && IM.vertical > 0 && KPH <= 1)
{
reverse = false;
//gearNum = 0;
}
if (engineRPM >= maxShiftRPM && gearNum < gears.Length - 1 && KPH >= wheelsSpeedMax - 20 && /*|| KPH >= wheelsSpeedMax - (10 * gears.Length - (10 * (gearNum / gears.Length))) &&*/ !reverse)
{
gearNum += 1;
wasInvoked = true;
setEngineLerp(engineRPM);
/*if (engineRPM > engineLerpValue)
{
engineRPM = Mathf.Lerp(engineRPM, engineLerpValue, lerpSmoothTime); && GearAutoShifttimer > GearDelaytimeValue
}
else
{
engineRPM = engineRPM;
}*/
}
if (engineRPM <= minShiftRPM && gearNum > 0 && KPH <= ((minShiftRPM * (1 / Mathf.Clamp(vertical, 0.5f, 0.75f) + BrakeValue)) / gearSize / (gears[gearNum]) / 60 * Obwod * 3600 / 1000) && !reverse)
{
gearNum -= 1;
wasInvoked = true;
setEngineLerp(engineRPM);
/*if(engineRPM > engineLerpValue)
{
engineRPM = Mathf.Lerp(engineRPM, engineLerpValue, lerpSmoothTime);
}
else
{
engineRPM = engineRPM;
}*/
}
if (reverse && KPH <= 0 && vertical > 0)
{
gearNum += 1;
wasInvoked = true;
setEngineLerp(engineRPM);
}
}
if (manualSequentional)
{
if (CanItShiftAutomaticly)
{
if (!itsGrounded()) return;
if (!itsGotTraction()) return;
if (clutch) return;
if (!reverse && IM.vertical < 0 && gearNum == 0 && KPH <= 1)
{
reverse = true;
}
else if (reverse && IM.vertical > 0 && KPH <= 1)
{
reverse = false;
//gearNum = 0;
}
if (engineRPM >= maxShiftRPM && gearNum < gears.Length - 1 && KPH >= wheelsSpeedMax - 20/*|| KPH >= wheelsSpeedMax - (10 * gears.Length - (10 * (gearNum / gears.Length))) &&*/&& !reverse)
{
gearNum += 1;
CheckSD = 0;
wasInvoked = true;
setEngineLerp(engineRPM);
/*if (engineRPM > engineLerpValue)
{
engineRPM = Mathf.Lerp(engineRPM, engineLerpValue, lerpSmoothTime); && GearAutoShifttimer > GearDelaytimeValue
}
else
{
engineRPM = engineRPM;
}*/
}
if (engineRPM <= minShiftRPM && gearNum > 0 && KPH <= ((minShiftRPM * (1 / Mathf.Clamp(vertical, 0.5f, 0.75f) + BrakeValue)) / gearSize / (gears[gearNum]) / 60 * Obwod * 3600 / 1000) && !reverse)
{
gearNum -= 1;
CheckSD = 0;
wasInvoked = true;
setEngineLerp(engineRPM);
/*if(engineRPM > engineLerpValue)
{
engineRPM = Mathf.Lerp(engineRPM, engineLerpValue, lerpSmoothTime);
}
else
{
engineRPM = engineRPM;
}*/
}
if (reverse && KPH <= 0 && vertical > 0)
{
gearNum += 1;
wasInvoked = true;
setEngineLerp(engineRPM);
}
}
else
{
if (reverse && GearDown || !reverse && GearDown && gearNum == 0)
{
reverse = true;
CheckSD = 0;
}
else if (reverse && GearUp)
{
reverse = false;
gearNum -= 1;
CheckSD = 0;
}
if (GearUp && gearNum < gears.Length - 1 && !reverse)
{
gearNum += 1;
CheckSD = 0;
}
if (GearDown && gearNum > 0 && !reverse)
{
gearNum -= 1;
CheckSD = 0;
}
}
}
}
private void headlight()
{
if (Input.GetKeyDown(KeyCode.L))
{
if (LightCount >= 2) LightCount = 0;
else LightCount++;
}
//if (Input.GetKeyDown(KeyCode.L) && ActiveHeadlightLong && !ActiveHeadlight)
if (LightCount == 0)
{
ActiveHeadlight = false;
ActiveHeadlightLong = false;
if (CanItUseMaterialTo_Light)
{
LightMat2.DisableKeyword("_EMISSION");
LightMat3.DisableKeyword("_EMISSION");
}
}
//else if(Input.GetKeyDown(KeyCode.L) && !ActiveHeadlight && !ActiveHeadlightLong)
if (LightCount == 1)
{
ActiveHeadlight = true;
ActiveHeadlightLong = false;
if (CanItUseMaterialTo_Light)
{
LightMat2.EnableKeyword("_EMISSION");
LightMat3.EnableKeyword("_EMISSION");
}
}
//else if (Input.GetKeyDown(KeyCode.L) && ActiveHeadlight && !ActiveHeadlightLong)
if (Input.GetKey(KeyCode.K) || LightCount == 2)
{
ActiveHeadlight = false;
ActiveHeadlightLong = true;
if (CanItUseMaterialTo_Light)
{
LightMat2.EnableKeyword("_EMISSION");
LightMat3.EnableKeyword("_EMISSION");
}
}
for (int i = 0; i < headlightObject.Length; i++)
{
if (ActiveHeadlight)
{
headlightObject[i].SetActive(true);
}
else
{
headlightObject[i].SetActive(false);
}
}
for (int l = 0; l < headlightLongObject.Length; l++)
{
if (ActiveHeadlightLong)
{
headlightLongObject[l].SetActive(true);
}
else
{
headlightLongObject[l].SetActive(false);
}
}
for (int i = 0; i < headlightLongObject.Length; i++)
{
if (ActiveHeadlightLong)
{
//ActiveHeadlightLong = true;
headlightLongObject[i].SetActive(true);
}
else
{
headlightLongObject[i].SetActive(false);
}
}
if (antiSmokeheadlightObject.Length > 0)
{
for (int i = 0; i < antiSmokeheadlightObject.Length; i++)
{
if (ActiveASHeadlight)
{
antiSmokeheadlightObject[i].SetActive(true);
}
else if (!ActiveASHeadlight)
{
antiSmokeheadlightObject[i].SetActive(false);
}
}
}
if (reverse)
{
/*for (int b = 0; b < ReverseLightsParticle.Length; b++)
{
if (CanItUseMaterialTo_Light)
{
LightMat2.EnableKeyword("_EMISSION");
LightMat3.EnableKeyword("_EMISSION");
}
if (CanItUseMaterialTo_Reverse)
{
LightMat4.EnableKeyword("_EMISSION");
}
if (CanItUseMaterialTo_Brake)
{
LightMat1.EnableKeyword("_EMISSION");
}
}*/
if (CanItUseMaterialTo_Reverse)
{
LightMat4.EnableKeyword("_EMISSION");
}
for (int p = 0; p < ReverseLightsParticle.Length; p++)
{
if (!ReverseLightsParticle[p].isPlaying)
{
ReverseLightsParticle[p].Play();
}
}
}
else
{
/*for (int b = 0; b < lightObject.Length; b++)
{
lightObject[b].SetActive(false);
}*/
if (CanItUseMaterialTo_Reverse)
{
LightMat4.DisableKeyword("_EMISSION");
}
for (int p = 0; p < ReverseLightsParticle.Length; p++)
{
if (!ReverseLightsParticle[p].isStopped)
{
ReverseLightsParticle[p].Stop();
}
}
}
if (BrakeValue >= 0.01f)
{
for (int p = 0; p < BrakeParticle.Length; p++)
{
if (!BrakeParticle[p].isPlaying)
{
BrakeParticle[p].Play();
}
}
for (int b = 0; b < lightObject.Length; b++)
{
lightObject[b].SetActive(true);
}
if (CanItUseMaterialTo_Brake)
{
LightMat1.EnableKeyword("_EMISSION");
}
}
else
{
for (int p = 0; p < BrakeParticle.Length; p++)
{
if (!BrakeParticle[p].isStopped)
{
BrakeParticle[p].Stop();
}
}
for (int b = 0; b < lightObject.Length; b++)
{
lightObject[b].SetActive(false);
}
if (CanItUseMaterialTo_Brake)
{
LightMat1.DisableKeyword("_EMISSION");
}
}
}
public void steerVehicle()
{
vertical = IM.vertical;
horizontal = Mathf.Lerp(horizontal, IM.horizontal, (IM.horizontal != 0) ? 2 * Time.deltaTime : 3 * Time.deltaTime);
float steerMaxL = Mathf.Atan(wheelsBase / (finalTurnAngle - (-rearTrackSize / 2)));
float steerMaxR = Mathf.Atan(wheelsBase / (finalTurnAngle + (-rearTrackSize / 2)));
float CSvalue = CounterSteerHelp / 100;
AngleDrift = Vector3.Angle(rigidbody.transform.forward, (rigidbody.velocity + rigidbody.transform.forward).normalized);
DriftForceSteer = rigidbody.transform.InverseTransformDirection(rigidbody.velocity) / (Time.deltaTime * 1000);
if (EnableAntiUnderSteerHelp && reverse && wheelsRPM < 0 || EnableAntiUnderSteerHelp && !reverse && wheelsRPM > 0)
{
UnderSteerValue = Mathf.Clamp((Mathf.Clamp(KPH, 1, 50) / 50) / (1 / Mathf.Clamp(Mathf.Abs(Sslip[0] + Sslip[1]), 0.5f, 1)), 0f, 0.75f);
}
else
{
UnderSteerValue = 0;
}
if (KPH > speedStart1 && EnableCounterSteerHelp && !reverse && wheelsRPM > 0 || KPH > speedStart1 && EnableCounterSteerHelp && reverse && wheelsRPM < 0)
{
if (AWD)
{
for (int i = 0; i < wheels.Length; i++)
{
if (!ActivatedCurveOfSteerAsist)
{
//SteerValue = horizontal + ((Sslip[i]) * CSvalue / (FtRPowerTransfer / 50));
SteerValue = (horizontal * (1 - UnderSteerValue)) + ((Mathf.Abs(Sslip[i]) * -Mathf.Sign(Sslip[i])) * CSvalue / (FtRPowerTransfer / 50) * (1 - Mathf.Clamp(GasValue, 0f, 0.5f)));
}
else
{
SteerValue = (horizontal * (1 - UnderSteerValue)) - (CurveOfSteerAsist.Evaluate((Mathf.Abs(Sslip[i]))) * -Mathf.Sign(Sslip[i]) * Mathf.Abs(Fslip[i] / 4 + 1) * CSvalue / (FtRPowerTransfer / 50) * (1 - Mathf.Clamp(GasValue, 0f, 0.5f)));
}
}
}
else if (RWD)
{
for (int i = 2; i < wheels.Length; i++)
{
if (!ActivatedCurveOfSteerAsist)
{
if (customSteeringSystem)
{
SteerValue = (horizontal * (1 - UnderSteerValue)) + (Sslip[i]) * (((MaxSteerAngle / (0.5f * MaxSteerAngle))) * Mathf.Abs((Fslip[i] / 2) + 1) * (CSvalue * 2));
}
else
{
SteerValue = (horizontal * (1 - UnderSteerValue)) + ((Mathf.Abs(Sslip[i]) * -Mathf.Sign(Sslip[i])) * (CSvalue * 2) / (wheelsBase * (finalTurnAngle + rearTrackSize)));
}
}
else
{
//SteerValue = horizontal - (CurveOfSteerAsist.Evaluate((Mathf.Abs(Sslip[i] * (1f + (Mathf.Clamp(KPH, speedStart1, speedEnd1) / speedEnd1))))) * -Mathf.Sign(Sslip[i]) * (Mathf.Abs(((0.75f + (Fslip[i] * Sslip[i])) + (Mathf.Clamp(KPH, 0, speedStart1) / speedStart1) * (Mathf.Clamp(KPH, speedStart1, speedEnd1) / speedEnd1))) + (Fslip[i] / finalTurnAngle)) * CSvalue);
if (customSteeringSystem)
{
//SteerValue = horizontal - (CurveOfSteerAsist.Evaluate((Mathf.Abs(Sslip[i] / ((MaxSteerAngle + ((aacOrAcValue * MaxSteerAngle) / 100)) / 45)))) * ((MaxSteerAngle / 90) + ((aacOrAcValue * MaxSteerAngle) / 100) / 45) * -Mathf.Sign(Sslip[i]) * Mathf.Abs((Fslip[i] / 2 * (MaxSteerAngle / 45) + 2)) * CSvalue / (MaxSteerAngle / 45));
SteerValue = (horizontal * (1 - UnderSteerValue)) - (CurveOfSteerAsist.Evaluate(Mathf.Abs(Sslip[i])) * -Mathf.Sign(Sslip[i]) * Mathf.Abs((Fslip[i] / 4) + 1) * CSvalue * 2);
}
else
{
//float steerMaxL = Mathf.Atan(wheelsBase / (finalTurnAngle - (-rearTrackSize / 2)));
//float steerMaxR = Mathf.Atan(wheelsBase / (finalTurnAngle + (-rearTrackSize / 2)));
SteerValue = (horizontal * (1 - UnderSteerValue)) - (CurveOfSteerAsist.Evaluate(Mathf.Abs(Sslip[i])) * -Mathf.Sign(Sslip[i]) * Mathf.Abs((Fslip[i] / 4) + 1) * CSvalue * 2);
//SteerValue = horizontal - (CurveOfSteerAsist.Evaluate(Mathf.Abs(Sslip[i])) * (4 * (steerMaxL + steerMaxR / 2)) * -Mathf.Sign(Sslip[i]) * Mathf.Abs((Fslip[i] / 4) + 1) * CSvalue * 2);((steerMaxL + steerMaxR) / 2)
}
}
}
}
else
{
for (int i = 0; i < wheels.Length; i++)
{
if (!ActivatedCurveOfSteerAsist)
{
if (customSteeringSystem)
{
SteerValue = (horizontal * (1 - UnderSteerValue)) + (Sslip[i]) * (((MaxSteerAngle / (0.5f * MaxSteerAngle))) * Mathf.Abs((Fslip[i] / 2) + 1) * (CSvalue * 2));
}
else
{
SteerValue = (horizontal * (1 - UnderSteerValue)) + ((Mathf.Abs(Sslip[i]) * -Mathf.Sign(Sslip[i])) * (CSvalue * 2) / (wheelsBase * (finalTurnAngle + rearTrackSize)));
}
}
else
{
//SteerValue = horizontal - (CurveOfSteerAsist.Evaluate((Mathf.Abs(Sslip[i] * (1f + (Mathf.Clamp(KPH, speedStart1, speedEnd1) / speedEnd1))))) * -Mathf.Sign(Sslip[i]) * (Mathf.Abs(((0.75f + (Fslip[i] * Sslip[i])) + (Mathf.Clamp(KPH, 0, speedStart1) / speedStart1) * (Mathf.Clamp(KPH, speedStart1, speedEnd1) / speedEnd1))) + (Fslip[i] / finalTurnAngle)) * CSvalue);
if (customSteeringSystem)
{
//SteerValue = horizontal - (CurveOfSteerAsist.Evaluate((Mathf.Abs(Sslip[i] / ((MaxSteerAngle + ((aacOrAcValue * MaxSteerAngle) / 100)) / 45)))) * ((MaxSteerAngle / 90) + ((aacOrAcValue * MaxSteerAngle) / 100) / 45) * -Mathf.Sign(Sslip[i]) * Mathf.Abs((Fslip[i] / 2 * (MaxSteerAngle / 45) + 2)) * CSvalue / (MaxSteerAngle / 45));
SteerValue = (horizontal * (1 - UnderSteerValue)) - (CurveOfSteerAsist.Evaluate(Mathf.Abs(Sslip[i])) * -Mathf.Sign(Sslip[i]) * Mathf.Abs((Fslip[i] / 4) + 1) * CSvalue * 2);
}
else
{
//float steerMaxL = Mathf.Atan(wheelsBase / (finalTurnAngle - (-rearTrackSize / 2)));
//float steerMaxR = Mathf.Atan(wheelsBase / (finalTurnAngle + (-rearTrackSize / 2)));
SteerValue = (horizontal * (1 - UnderSteerValue)) - (CurveOfSteerAsist.Evaluate(Mathf.Abs(Sslip[i])) * -Mathf.Sign(Sslip[i]) * Mathf.Abs((Fslip[i] / 4) + 1) * CSvalue * 2);
//SteerValue = horizontal - (CurveOfSteerAsist.Evaluate(Mathf.Abs(Sslip[i])) * (4 * (steerMaxL + steerMaxR / 2)) * -Mathf.Sign(Sslip[i]) * Mathf.Abs((Fslip[i] / 4) + 1) * CSvalue * 2);((steerMaxL + steerMaxR) / 2)
}
}
}
}
if (SteerValue >= 1)
{
SteerValue = 1;
}
else if (SteerValue <= -1)
{
SteerValue = -1;
}
else
{
SteerValue = SteerValue;
}
}
else if (KPH < speedStart1 && EnableCounterSteerHelp && !reverse && wheelsRPM >= 0 || KPH < speedStart1 && EnableCounterSteerHelp && reverse && wheelsRPM <= 0)
{
if (RWD)
{
for (int i = 2; i < wheels.Length; i++)
{
if (!ActivatedCurveOfSteerAsist)
{
if (customSteeringSystem)
{
SteerValue = (horizontal * (1 - UnderSteerValue)) + ((Sslip[i]) * (((MaxSteerAngle / (0.5f * MaxSteerAngle))) * Mathf.Abs((Fslip[i] / 2) + 1) * (CSvalue * 2))) * (KPH / speedStart1);
}
else
{
SteerValue = (horizontal * (1 - UnderSteerValue)) + ((Mathf.Abs(Sslip[i]) * -Mathf.Sign(Sslip[i])) * (CSvalue * 2) / (wheelsBase * (finalTurnAngle + rearTrackSize))) * (KPH / speedStart1);
}
}
else
{
//SteerValue = horizontal - (CurveOfSteerAsist.Evaluate((Mathf.Abs(Sslip[i] * (1f + (Mathf.Clamp(KPH, speedStart1, speedEnd1) / speedEnd1))))) * -Mathf.Sign(Sslip[i]) * (Mathf.Abs(((0.75f + (Fslip[i] * Sslip[i])) + (Mathf.Clamp(KPH, 0, speedStart1) / speedStart1) * (Mathf.Clamp(KPH, speedStart1, speedEnd1) / speedEnd1))) + (Fslip[i] / finalTurnAngle)) * CSvalue);
if (customSteeringSystem)
{
//SteerValue = horizontal - (CurveOfSteerAsist.Evaluate((Mathf.Abs(Sslip[i] / ((MaxSteerAngle + ((aacOrAcValue * MaxSteerAngle) / 100)) / 45)))) * ((MaxSteerAngle / 90) + ((aacOrAcValue * MaxSteerAngle) / 100) / 45) * -Mathf.Sign(Sslip[i]) * Mathf.Abs((Fslip[i] / 2 * (MaxSteerAngle / 45) + 2)) * CSvalue / (MaxSteerAngle / 45));
SteerValue = (horizontal * (1 - UnderSteerValue)) - (CurveOfSteerAsist.Evaluate(Mathf.Abs(Sslip[i])) * -Mathf.Sign(Sslip[i]) * Mathf.Abs((Fslip[i] / 4) + 1) * CSvalue * 2) * (KPH / speedStart1);
}
else
{
//float steerMaxL = Mathf.Atan(wheelsBase / (finalTurnAngle - (-rearTrackSize / 2)));
//float steerMaxR = Mathf.Atan(wheelsBase / (finalTurnAngle + (-rearTrackSize / 2)));
SteerValue = (horizontal * (1 - UnderSteerValue)) - (CurveOfSteerAsist.Evaluate(Mathf.Abs(Sslip[i])) * -Mathf.Sign(Sslip[i]) * Mathf.Abs((Fslip[i] / 4) + 1) * CSvalue * 2) * (KPH / speedStart1);
//SteerValue = horizontal - (CurveOfSteerAsist.Evaluate(Mathf.Abs(Sslip[i])) * (4 * (steerMaxL + steerMaxR / 2)) * -Mathf.Sign(Sslip[i]) * Mathf.Abs((Fslip[i] / 4) + 1) * CSvalue * 2);((steerMaxL + steerMaxR) / 2)
}
}
}
}
else
{
SteerValue = (horizontal * (1 - UnderSteerValue));
}
}
else
{
SteerValue = (horizontal * (1 - UnderSteerValue));
}
aacOrAcValue = Mathf.Atan(wheelsBase / (MaxSteerAngle - (-rearTrackSize / 2))) * (AntiAckermanOrAckermanValue / 100);
if (!customSteeringSystem)
{
//finalTurnAngle = (radius > 5) ? radius : 5;
if (SteerValue > 0)
{
wheels[0].steerAngle = Mathf.Rad2Deg * SteerValue * Mathf.Atan(wheelsBase / (finalTurnAngle - (-rearTrackSize / 2)));
wheels[1].steerAngle = Mathf.Rad2Deg * SteerValue * Mathf.Atan(wheelsBase / (finalTurnAngle + (-rearTrackSize / 2)));
}
else if (SteerValue < 0)
{
wheels[0].steerAngle = Mathf.Rad2Deg * SteerValue * Mathf.Atan(wheelsBase / (finalTurnAngle + (-rearTrackSize / 2)));
wheels[1].steerAngle = Mathf.Rad2Deg * SteerValue * Mathf.Atan(wheelsBase / (finalTurnAngle - (-rearTrackSize / 2)));
}
else
{
wheels[0].steerAngle = 0;
wheels[1].steerAngle = 0;
}
}
else
{
//finalTurnAngle = finalTurnAngle;
if (SteerValue > 0)
{
wheels[0].steerAngle = SteerValue * (MaxSteerAngle - aacOrAcValue);
wheels[1].steerAngle = SteerValue * (MaxSteerAngle + aacOrAcValue);
}
else if (SteerValue < 0)
{
wheels[0].steerAngle = SteerValue * (MaxSteerAngle + aacOrAcValue);
wheels[1].steerAngle = SteerValue * (MaxSteerAngle - aacOrAcValue);
}
else
{
wheels[0].steerAngle = 0;
wheels[1].steerAngle = 0;
}
}
if (fourWheelsSteering)
{
if (ItGotSteerCurveBehaviour)
{
wheels[2].steerAngle = RearWheelsSteerValue * SteerCurveBehaviour.Evaluate(KPH / speedDynamic) * SteerValue;
wheels[3].steerAngle = RearWheelsSteerValue * SteerCurveBehaviour.Evaluate(KPH / speedDynamic) * SteerValue;
}
else
{
wheels[2].steerAngle = RearWheelsSteerValue * SteerValue;
wheels[3].steerAngle = RearWheelsSteerValue * SteerValue;
}
}
else
{
wheels[2].steerAngle = 0;
wheels[3].steerAngle = 0;
}
if (!Burnout)
{
if (IM.vertical > 0 && !reverse || IM.vertical > 0 && reverse && manualSequentional && !CanItShiftAutomaticly)
{
GasValue = 1 * Mathf.Clamp(IM.vertical, 0f, 1f);
}
else if (IM.vertical < 0 && Automatic && reverse || manualSequentional && CanItShiftAutomaticly && IM.vertical < 0 && reverse)
{
GasValue = 1 * -Mathf.Clamp(IM.vertical, -1f, 0f);
}
else
{
GasValue = 0;
}
if (IM.vertical < 0 && !reverse || IM.vertical < 0 && reverse && manualSequentional && !CanItShiftAutomaticly)
{
BrakeValue = 1 * -Mathf.Clamp(IM.vertical, -1f, 0f);
}
else if (IM.vertical > 0 && reverse && Automatic || manualSequentional && CanItShiftAutomaticly && IM.vertical > 0 && reverse)
{
BrakeValue = 1 * Mathf.Clamp(IM.vertical, 0f, 1f);
}
else
{
BrakeValue = 0;
}
}
brakingSystem();
moveVehicle();
}
private void brakingSystem()
{
for (int i = 0; i < wheels.Length; i++)
{
float[] FB = new float[4];
FB[0] = FB[1] = FrontBrakePower * BrakeValue;
FB[2] = FB[3] = RearBrakePower * BrakeValue;
//wheels[0].brakeTorque = wheels[1].brakeTorque = FrontBrakePower * BrakeValue;
//wheels[3].brakeTorque = wheels[2].brakeTorque = RearBrakePower * BrakeValue;
wheels[i].brakeTorque = FB[i];
if (IM.handbrake && !Burnout)
{
wheels[3].brakeTorque = wheels[2].brakeTorque = HandbrakePower;
}
if (ABS && !IM.handbrake && !Burnout)
{
if (Mathf.Abs(Fslip[i]) > MaxFSlipABS)
{
wheels[i].brakeTorque = FB[i] * Mathf.Clamp(1 - Mathf.Abs(Fslip[i]) * (FB[i] * ABSPower), 0, FB[i]) * BrakeValue;
}
if (Mathf.Abs(Sslip[i]) > MaxSSlipABS)
{
wheels[i].brakeTorque = FB[i] * Mathf.Clamp(1 - Mathf.Abs(Sslip[i] / 4f) * (FB[i] * ABSPower * 20), 0, FB[i]) * BrakeValue;
}
}
if (ESC && !IM.handbrake && !Burnout)
{
if (Mathf.Abs(Sslip[i]) > 0 && !reverse)
{
GasValue = Mathf.Clamp(GasValue - Mathf.Clamp(Mathf.Abs(Sslip[i]) / 2, 0, 1), 0, 1);
if (Sslip[2] < -MaxSSlipESC)
{
wheels[0].brakeTorque = FrontBrakePower * ((Mathf.Abs(Sslip[0]) / 2) * (ESCPower / 100));
wheels[2].brakeTorque = RearBrakePower * (Mathf.Abs(Sslip[2] * (1 - Mathf.Abs(Fslip[2]))) * (ESCPower / 100));
}
else if (Sslip[3] > MaxSSlipESC)
{
wheels[1].brakeTorque = FrontBrakePower * ((Mathf.Abs(Sslip[1]) / 2) * (ESCPower / 100));
wheels[3].brakeTorque = RearBrakePower * (Mathf.Abs(Sslip[3] * (1 - Mathf.Abs(Fslip[3]))) * (ESCPower / 100));
}
}
}
}
}
private void moveVehicle()
{
//if (!TSC) return;
float TCLevelLose = 1f + (TCLevel / 5f);
/*if (wheelsSpeed > wheelsSpeedMax && KPH < wheelsSpeedMax && itsGrounded() || !itsGrounded() && wheelsSpeed > wheelsSpeedMax)
{
//engineRPM = Mathf.Clamp(engineRPM, 0, maxRPM);
engineDamp = true;
}*/
for (int i = 0; i < wheels.Length; i++)
{
wheelsPower[i] = wheels[i].motorTorque;
if (TSC)
{
if (Mathf.Abs(Fslip[i]) > MaxFSlip && GasValue > 0f && Mathf.Abs(wheels[i].rpm) / 4 > 20 && !engineLerp && GasValue > 0)
{
if (RWD)
{
BrakesTorque[0] = BrakesTorque[0];
BrakesTorque[1] = BrakesTorque[1];
BrakesTorque[2] = ((RearBrakePower / 10) / (10 / TCLevelLose)) * Mathf.Clamp((TCCurve.Evaluate(Mathf.Abs(Fslip[2])) / TCLevelLose / 2), 0f, 1f);
BrakesTorque[3] = ((RearBrakePower / 10) / (10 / TCLevelLose)) * Mathf.Clamp((TCCurve.Evaluate(Mathf.Abs(Fslip[3])) / TCLevelLose / 2), 0f, 1f);
TSCPowerReduction = Mathf.Clamp(1 - (0.75f * TCLevelLose * Mathf.Clamp(Mathf.Pow(engineOnlyPower, 2) / (10 * Mathf.Abs((Fslip[2]) + Mathf.Abs(Fslip[3]) / 2)), MaxFSlip * 2, 1)), 0, 1); //1 -Mathf.Clamp((1 * TCCurve.Evaluate((Mathf.Abs(Fslip[2]) + Mathf.Abs(Fslip[3])) / 2) * 1000 / TCLevelLose / 2), 0f, 1);
}
else if (AWD)
{
BrakesTorque[i] = ((brakePower / 10) * Mathf.Abs(engineOnlyPower) / (10 / TCLevelLose)) * Mathf.Clamp((TCCurve.Evaluate(Mathf.Abs(Fslip[i])) / TCLevelLose / 4), 0f, 0.75f);
TSCPowerReduction = Mathf.Clamp(1 - (0.75f * TCLevelLose * Mathf.Clamp(Mathf.Pow(engineOnlyPower, 2) / (10 * Mathf.Abs(Fslip[i] / 4)), MaxFSlip * 2, 1)), 0, 1); //1 - Mathf.Clamp((1 * TCCurve.Evaluate(Mathf.Abs(Fslip[i] / 4)) * 1000 / TCLevelLose / 4), 0f, 1);
}
else
{
BrakesTorque[0] = ((FrontBrakePower / 10) / (10 / TCLevelLose)) * Mathf.Clamp((TCCurve.Evaluate(Mathf.Abs(Fslip[0])) / TCLevelLose / 2), 0f, 1);
BrakesTorque[1] = ((FrontBrakePower / 10) / (10 / TCLevelLose)) * Mathf.Clamp((TCCurve.Evaluate(Mathf.Abs(Fslip[1])) / TCLevelLose / 2), 0f, 1);
BrakesTorque[2] = BrakesTorque[2];
BrakesTorque[3] = BrakesTorque[3];
TSCPowerReduction = Mathf.Clamp(1 - (0.75f * TCLevelLose * Mathf.Clamp(Mathf.Pow(engineOnlyPower, 2) / (10 * Mathf.Abs((Fslip[0]) + Mathf.Abs(Fslip[1]) / 2)), MaxFSlip * 2, 1)), 0, 1);//1 - Mathf.Clamp((1 * TCCurve.Evaluate(Mathf.Abs((Fslip[0]) + Mathf.Abs(Fslip[1]) / 2)) * 1000 / TCLevelLose / 2), 0f, 1);
}
}
/*else if (Mathf.Abs(Sslip[i]) > MaxSSlip)
{
TSCPowerReduction = 0;//Mathf.Lerp(TSCPowerReduction, Mathf.Clamp(1 - (1 * Mathf.Clamp(Mathf.Abs(Sslip[i]), 0f, 1f) / TCLevelLose), 0f, 1), Time.deltaTime);
// BrakesTorque[i] = BrakesTorque[i];
}*/
else
{
TSCPowerReduction = Mathf.Lerp(TSCPowerReduction, 1, Time.deltaTime * Mathf.Clamp(1 - Fslip[i], 0, 1) / EngineSmoothTime);
}
}
else if (!TSC)
{
//BrakesTorque[i] = BrakesTorque[i];
TSCPowerReduction = 1;
}
}
if (Input.GetKey(KeyCode.UpArrow) && Input.GetKey(KeyCode.DownArrow) || Input.GetKey(KeyCode.W) && Input.GetKey(KeyCode.S))
{
Burnout = true;
GasValue = 1;
BrakeValue = 0;
if (RWD)
{
wheels[0].brakeTorque = wheels[1].brakeTorque = FrontBrakePower;
}
else if (FWD)
{
IM.handbrake = true;
}
else
{
clutch = true;
}
}
else
{
Burnout = false;
}
//if (engineRPM > engineLerpValue && !engineDamp)
/*if(wheelsSpeed > wheelsSpeedMax && KPH < wheelsSpeedMax && itsGrounded() || !itsGrounded() && wheelsSpeed > wheelsSpeedMax)
{
totalPower = 0;
}*/
if (Input.GetKey(KeyCode.X) || wheelsSpeed > wheelsSpeedMax && KPH < wheelsSpeedMax && itsGrounded() || !itsGrounded() && wheelsSpeed > wheelsSpeedMax)
{
clutch = true;
engineDamp = true;
}
else
{
clutch = false;
engineDamp = false;
}
KPH = rigidbody.velocity.magnitude * 3.6f;
/*if(drive == driveType.FrontWheelDrive)
{
FWD = true;
RWD = false;
AWD = false;
}else if(drive == driveType.RearWheelDrive)
{
FWD = false;
RWD = true;
AWD = false;
}
else
{
FWD = false;
RWD = false;
AWD = true;
}*/
//float TCLevelLose = Mathf.Sqrt(TCLevel / 4.5f);
}
private void wheelGrip()
{
if (TPS == null)
{
TPS = GameObject.Find(ParentName).GetComponent<TireParentVariableSet>();
tireStifF_Road = TPS.TireAsphaltPower_F;
tireStifS_Road = TPS.TireAsphaltPower_S;
tireStifF_Gravel = TPS.TireGrawelPower_F;
tireStifS_Gravel = TPS.TireGrawelPower_S;
TireSnowReductionA_F = TPS.TireSnowReductionA_F;
TireSnowReductionA_S = TPS.TireSnowReductionA_S;
TireSnowReductionG_F = TPS.TireSnowReductionG_F;
TireSnowReductionG_S = TPS.TireSnowReductionG_S;
TireRainReductionA_F = TPS.TireRainReductionA_F;
TireRainReductionA_S = TPS.TireRainReductionA_S;
TireRainReductionG_F = TPS.TireRainReductionG_F;
TireRainReductionG_S = TPS.TireRainReductionG_S;
SSF = TPS.SlipSfactor;
FSF = TPS.ForceSFfactor;
}
for (int i = 2; i < wheels.Length; i++)
{
TireHardnes[i] = TireHardnesOnRearWheels;
}
for (int i = 0; i < wheels.Length - 2; i++)
{
TireHardnes[i] = TireHardnesOnFrontWheels;
}
for (int i = 0; i < wheels.Length; i++)
{
wheelWidth[0] = wheelWidth[1] = wheelWidthF;
wheelWidth[2] = wheelWidth[3] = wheelWidthR;
wheelsrim[0] = wheelsrim[1] = wheelsrimF;
wheelsrim[2] = wheelsrim[3] = wheelsrimR;
tireRadio[i] = (wheels[i].radius - wheelsrim[i]) / wheelWidth[i];
Slip2Ddim[i] = Mathf.Abs(Fslip[i]) + Mathf.Abs(Sslip[i] / 1.5f);
SlipRatio[i] = Mathf.Abs(Fslip[i]);
//velocityAngularDist =
TireStiffnes[i] = (forwardFriction[i].stiffness + sidewaysFriction[i].stiffness) / 2;
cg = (TireGripClass) / 20;
float[] CWF = new float[4];
CWF[0] = 1;
CWF[1] = -1;
CWF[2] = 1;
CWF[3] = -1;
SFC = CGFCurve.Evaluate(Mathf.Abs((TranswheelMesh[i].transform.localRotation.x / 100) * Mathf.Sign(CWF[i])) + Mathf.Abs(Sslip[i]));
if (SceneManager.GetActiveScene().name != "Menu Garage Scene" && ParentName != null && !ItUsingJob)
{
//sidewaysFriction[i].stiffness = tireStifS * 1 * tireLerpRadiusSideways * cg - tireRadio + wheelWidth / tireFlexGrip[i] *(WForce[i] / 1000 / TireHardnes[i]) - Mathf.Clamp(Mathf.Abs(Mathf.Clamp(wheels[i].rpm, 0f, 10000 / (-TireHardnesLT[i]) + tireRadio * wheelWidth) / 10000) * (-TireHardnesLT[i])
// wc * WCGC.ev(Sslip + wc) TranswheelMesh[0].transform.localRotation
/*sidewaysFriction[i] = wheels[i].sidewaysFriction;
sidewaysFriction[i].stiffness = (tireStifSBase[i] / 1f) * (((wheelForceFlexCurve.Evaluate(WForce[i] * ((wheelWidth[i] * 1) + (tireRadio[i] * 1) / (TireHardnes[i]))) * 1f) / Mathf.Clamp(SSF * Mathf.Clamp(Mathf.Abs(Sslip[i]) + (Mathf.Clamp(Mathf.Abs(Fslip[i] * 2), 1f, 2f) * 2), 0.5f,2f - tireRadio[i]), 2f, 10f)) * CGFCurve.Evaluate(Mathf.Abs((TranswheelMesh[i].transform.localRotation.x / 100) * Mathf.Sign(CWF[i])) + Mathf.Abs(Sslip[i]))) + cg;
sidewaysFriction[i].extremumValue = sidewaysFriction[i].asymptoteValue = (wheelSidewaysValueGrip.Evaluate(Slip2Ddim[i] + Mathf.Abs(Sslip[i] / (3 * Mathf.Sqrt(tireRadio[i] * 2)))) * 8) * ((wheelWidth[i] * 2) / (1f + Mathf.Sqrt(Mathf.Clamp(tireRadio[i] * 2, 1, 999999)) / 50)) - Mathf.Clamp(Mathf.Abs(Mathf.Clamp(wheels[i].rpm, 0f, 10000 / (-TireHardnes[i])) / 1000) * (-TireHardnes[i]) * ((tireRadio[i]* 10) + (wheelWidth[i] * 10)), 0f, tireRadio[i]);
sidewaysFriction[i].extremumSlip = sidewaysFriction[i].asymptoteSlip = (SlipAngleCurveTest.Evaluate(Mathf.Abs(Slip2Ddim[i] + Mathf.Clamp(Mathf.Abs(Sslip[i]),-0.5f,0.5f))) * (tireRadio[i] + 1f)) ;
wheels[i].sidewaysFriction = sidewaysFriction[i];
wheels[i].forceAppPointDistance = -(Mathf.Sqrt(tireStifFBase[i] * 1) * Mathf.Clamp(Mathf.Abs((Fslip[i] * (1 - Mathf.Clamp(10 * Mathf.Abs(Sslip[i]), 0, 1))) * Mathf.Clamp(wheels[i].rpm, 0.25f, 1) * ((Mathf.Sqrt(Mathf.Clamp(tireStifSBase[i], 0, 2)) * 1)) / (1 + 9 * Mathf.Abs(Sslip[i]))), 0, 0.5f)) - Mathf.Clamp(Mathf.Abs(Sslip[i] / 5f) * ((Mathf.Pow(tireRadio[i] + wheels[i].radius, 2) * 2)) * 2 * (Mathf.Clamp(wheels[i].rpm, 0.25f, 1)), 0, 0.025f);// * (Mathf.Clamp(Mathf.Abs(Fslip[i] - (Sslip[i] / 2)), 0.0025f, 0.05f) / 2) * ((tireRadio[i] + wheelWidth[i]) * 10)));// ; ; * Mathf.Clamp(Mathf.Abs(Sslip[i] * (2 + tireRadio[i] * 10)), 0, 0.01f + ((tireRadio[i] + wheelWidth[i]) / 10));
//wheels[i].forceAppPointDistance = -(Mathf.Sqrt(tireStifFBase[i] / 2) * Mathf.Clamp(Mathf.Abs(Fslip[i] / (2 + 2 * Mathf.Abs(Sslip[i]))) - Mathf.Abs(Sslip[i] / 5f), 0, 1) * (((Mathf.Pow(tireRadio[i] + wheels[i].radius, 2) / 10)))) * Mathf.Clamp(wheels[i].rpm, 0.5f, 1) + ((Mathf.Sqrt(Mathf.Clamp(tireStifSBase[i], 0, 2)) / 10) * (Mathf.Clamp(Mathf.Abs(Fslip[i] - (Sslip[i] / 2)), 0.0025f, 0.05f) / 2) * ((tireRadio[i] + wheelWidth[i]) / 10)) * Mathf.Clamp(Mathf.Abs(Sslip[i] * (2 + tireRadio[i] * 10)), 0, 0.01f + ((tireRadio[i] + wheelWidth[i]) / 10));
forwardFriction[i] = wheels[i].forwardFriction;
forwardFriction[i].stiffness = tireStifFBase[i] * (wheelForceFlexCurve.Evaluate(WForce[i] * ((wheelWidth[i] * 2) + (FSF * Mathf.Abs(Sslip[i] * Fslip[i] * Mathf.Clamp(1 - (tireRadio[i] * 10), 0.1f, 1) * (wheelWidth[i] * 2))) + (tireRadio[i]) / TireHardnes[i])) + (FCGFCurve.Evaluate(Mathf.Abs((TranswheelMesh[i].transform.localRotation.x / 100) * Mathf.Sign(CWF[i])) + Mathf.Abs(Sslip[i]))) * (Mathf.Clamp(Mathf.Abs(Fslip[i] * 2),0,0.25f) - (Mathf.Clamp(Mathf.Abs(Fslip[i] * 2), 0.5f, 0.75f) - 0.5f))) + cg;
//forwardFriction[i].extremumValue = forwardFriction[i].asymptoteValue = (wheelForwardValueGrip.Evaluate(Mathf.Abs(Fslip[i])) * (wheelWidth * 10) * (tireRadio * 10)) + Mathf.Clamp(Mathf.Abs(Mathf.Clamp(wheels[i].rpm, 0f, 10000 / (-TireHardnes[i])) / 10000) * (-TireHardnes[i]) * ((tireRadio) + (wheelWidth * 10)), 0f, 1f);
//forwardFriction[i].extremumSlip = forwardFriction[i].asymptoteSlip = (SlipAngleCurveTest.Evaluate(Mathf.Abs(Slip2Ddim[i] / ((wheelWidth * 2 * TireHardnes[i]) / 10))) * ((tireRadio * (2 * Mathf.Pow(1f + Mathf.Abs(Fslip[i]),2))))) * (SlipRatioCurveTest.Evaluate(Mathf.Abs(SlipRatio[i] / (tireRadio * 2)) * (tireRadio * 10) / (TireHardnes[i] / 2)));
forwardFriction[i].extremumValue = forwardFriction[i].asymptoteValue = (wheelForwardValueGrip.Evaluate(Slip2Ddim[i]) * (2 * (1 - (tireRadio[i]/ 2)) )) * (((wheelWidth[i] / 2) + tireRadio[i] * 2) * 1) + Mathf.Clamp(Mathf.Abs(Mathf.Clamp(wheels[i].rpm, 0f, 10000 / (-TireHardnes[i])) / 10000) * (-TireHardnes[i]) * ((tireRadio[i]) + (wheelWidth[i] * 10)), 0f, tireRadio[i] * 10);
forwardFriction[i].extremumSlip = forwardFriction[i].asymptoteSlip = (SlipAngleCurveTest.Evaluate(Mathf.Abs(Slip2Ddim[i] + Mathf.Clamp(Mathf.Abs(Fslip[i]), -0.5f, 0.5f)))) * (((tireRadio[i] * 1) / (wheelWidth[i] / 2)) / 1.25f) * ((SlipRatioCurveTest.Evaluate(Mathf.Abs(SlipRatio[i] * Mathf.Clamp(1.5f - (tireRadio[i] * 2), 1f, 1.25f))) * (2 / Mathf.Clamp(tireRadio[i], 1, 99999999999))) / Mathf.Clamp(Mathf.Abs(wheels[i].rpm), 0.5f, 1));
wheels[i].forwardFriction = forwardFriction[i];*/
/// Mathf.Clamp(SSF * Mathf.Clamp(Mathf.Abs(Sslip[i]) + (Mathf.Clamp(Mathf.Abs(Fslip[i] * 2), 1f, 2f) * 2), 0.5f,2f - tireRadio[i]), 2f, 10f))
sidewaysFriction[i] = wheels[i].sidewaysFriction;
sidewaysFriction[i].stiffness = Mathf.Clamp(tireStifSBase[i] * ((wheelForceFlexCurve.Evaluate(WForce[i] * ((Mathf.Clamp(wheelWidth[i] * 2, 0.1f, 0.65f)) + (tireRadio[i] * 1) / (TireHardnes[i]))) / Mathf.Clamp(SSF * Mathf.Clamp((Mathf.Abs(Sslip[i] * 1.25f) + Mathf.Clamp(Mathf.Abs((Fslip[i] * 1)) - Mathf.Abs(Sslip[i] * 2), 0, 2f)) * 1, 0.5f, 2f) - 0.5f, 0.75f, 10)) * CGFCurve.Evaluate(Mathf.Abs((TranswheelMesh[i].transform.localRotation.x / 100) * Mathf.Sign(CWF[i])) + Mathf.Abs(Sslip[i]))) + cg, 0, 2.5f * (1 * Mathf.Clamp(KPH / 30, 1, 4f)));
sidewaysFriction[i].extremumValue = sidewaysFriction[i].asymptoteValue = (wheelSidewaysValueGrip.Evaluate(Slip2Ddim[i] + Mathf.Clamp(Mathf.Abs(Sslip[i]), 0, 0.1f + (tireRadio[i] / 2 * (TireHardnes[i] / 3)))) * 4) * ((Mathf.Clamp(wheelWidth[i], 0.01f, 0.3f) * 2) / (1f + Mathf.Sqrt(Mathf.Clamp(tireRadio[i] * 2, 1, 999999)) / 20)) - Mathf.Clamp(Mathf.Abs(Mathf.Clamp(wheels[i].rpm, 0f, 10000 / (-TireHardnes[i])) / 10000) * (-TireHardnes[i]) * ((tireRadio[i] * 10) + (wheelWidth[i] * 10)), 0f, tireRadio[i] * 2);
sidewaysFriction[i].extremumSlip = sidewaysFriction[i].asymptoteSlip = (SlipAngleCurveTest.Evaluate(Mathf.Abs(Slip2Ddim[i] + Mathf.Clamp(Mathf.Abs(Sslip[i]), -0.5f, 0.5f))) * (tireRadio[i] + 2f)) * (/*SlipRatioCurveTest.Evaluate(Mathf.Abs((SlipRatio[i] + Mathf.Clamp(Mathf.Abs(Sslip[i] * 1.5f), 0, 1f)) / 1.5f)) */ ((2f - Mathf.Clamp(tireRadio[i] * 1, 0.1f, 0.75f)) * (0.5f + Mathf.Abs(Fslip[i])))); ;
wheels[i].sidewaysFriction = sidewaysFriction[i];
wheels[i].forceAppPointDistance = -(Mathf.Sqrt(tireStifFBase[i] * 1) * Mathf.Clamp(Mathf.Abs((Fslip[i] * (1 - Mathf.Clamp(10 * Mathf.Abs(Sslip[i]), 0, 1))) * Mathf.Clamp(wheels[i].rpm, 0.25f, 1) * ((Mathf.Sqrt(Mathf.Clamp(tireStifSBase[i], 0, 2)) * 1)) / (1 + 9 * Mathf.Abs(Sslip[i]))), 0, 0.5f)) - Mathf.Clamp(Mathf.Abs(Sslip[i] / 5f) * ((Mathf.Pow(tireRadio[i] + wheels[i].radius, 2) * 2)) * 2 * (Mathf.Clamp(wheels[i].rpm, 0.25f, 1)), 0, 0.025f);// * (Mathf.Clamp(Mathf.Abs(Fslip[i] - (Sslip[i] / 2)), 0.0025f, 0.05f) / 2) * ((tireRadio[i] + wheelWidth[i]) * 10)));// ; ; * Mathf.Clamp(Mathf.Abs(Sslip[i] * (2 + tireRadio[i] * 10)), 0, 0.01f + ((tireRadio[i] + wheelWidth[i]) / 10));
//wheels[i].forceAppPointDistance = -(Mathf.Sqrt(tireStifFBase[i] / 2) * Mathf.Clamp(Mathf.Abs(Fslip[i] / (2 + 2 * Mathf.Abs(Sslip[i]))) - Mathf.Abs(Sslip[i] / 5f), 0, 1) * (((Mathf.Pow(tireRadio[i] + wheels[i].radius, 2) / 10)))) * Mathf.Clamp(wheels[i].rpm, 0.5f, 1) + ((Mathf.Sqrt(Mathf.Clamp(tireStifSBase[i], 0, 2)) / 10) * (Mathf.Clamp(Mathf.Abs(Fslip[i] - (Sslip[i] / 2)), 0.0025f, 0.05f) / 2) * ((tireRadio[i] + wheelWidth[i]) / 10)) * Mathf.Clamp(Mathf.Abs(Sslip[i] * (2 + tireRadio[i] * 10)), 0, 0.01f + ((tireRadio[i] + wheelWidth[i]) / 10));
forwardFriction[i] = wheels[i].forwardFriction;
forwardFriction[i].stiffness = Mathf.Clamp(tireStifFBase[i] * (((wheelForceFlexCurve.Evaluate(WForce[i] * ((Mathf.Clamp(wheelWidth[i], 0.2f, 0.5f) * 2) + (FSF * Mathf.Abs(Sslip[i] * Mathf.Pow(Mathf.Abs(Fslip[i]) * 1.5f, 1.5f) * Mathf.Clamp(1 - (tireRadio[i] * 10), 0.1f, 1) * (wheelWidth[i] * 4))) + (tireRadio[i] * 4) / TireHardnes[i])) * Mathf.Clamp(1.5f - Mathf.Abs(Fslip[i]), 0.05f, 0.75f))) * FCGFCurve.Evaluate(Mathf.Abs((TranswheelMesh[i].transform.localRotation.x / 100) * Mathf.Sign(CWF[i])) + Mathf.Abs(Sslip[i]))) + cg, 0, 2.5f * (1 * Mathf.Clamp(KPH / 30, 1, 4f)));
forwardFriction[i].extremumValue = forwardFriction[i].asymptoteValue = (wheelForwardValueGrip.Evaluate(Slip2Ddim[i]) * 4) * (((Mathf.Clamp(wheelWidth[i], 0.1f, 0.5f) / 2) + (tireRadio[i] * Mathf.Clamp(2f * Mathf.Abs(Fslip[i]), 1, 2)) * 1) * 1) + Mathf.Clamp(Mathf.Abs(Mathf.Clamp(wheels[i].rpm, 0f, 10000 / (-TireHardnes[i])) / 10000) * (-TireHardnes[i]) * ((tireRadio[i]) + (wheelWidth[i] * 10)), 0f, tireRadio[i] * 10);
forwardFriction[i].extremumSlip = forwardFriction[i].asymptoteSlip = (SlipAngleCurveTest.Evaluate(Mathf.Abs(Slip2Ddim[i] + Mathf.Clamp(Mathf.Abs(Fslip[i]), -0.5f, 0.5f)))) * (((tireRadio[i] / 2) / (wheelWidth[i] / 2)) / 1.25f) * ((SlipRatioCurveTest.Evaluate(Mathf.Abs(SlipRatio[i] * Mathf.Clamp(1.5f - (tireRadio[i] / 2), 1f, 1.25f))) * (2 / Mathf.Clamp(tireRadio[i], 1, 99999999999))) / Mathf.Clamp(Mathf.Abs(wheels[i].rpm), 0.5f, 1));
wheels[i].forwardFriction = forwardFriction[i];
}
}
}
private bool itsGrounded()
{
if (wheels[0].isGrounded && wheels[1].isGrounded && wheels[2].isGrounded && wheels[3].isGrounded)
return true;
else
if (gearNum == 0 || KPH <= 2)
{
return true;
}
else
{
return false;
}
}
private bool itsGotTraction()
{
if (Mathf.Abs(Fslip[0]) < 0.5f && Mathf.Abs(Fslip[1]) < 0.5f && Mathf.Abs(Fslip[2]) < 0.5f && Mathf.Abs(Fslip[3]) < 0.5f)
return true;
else
return false;
}
void animateWheels()
{
for (int i = 0; i < wheels.Length; i++)
{
wheels[i].GetWorldPose(out wheelPosition, out wheelRotation);
//wheelPoint[i].position = wheelPosition;
TranswheelMesh[0].transform.localRotation = Quaternion.Euler(0, wheels[0].steerAngle, FwheelCamber);
TranswheelMesh[1].transform.localRotation = Quaternion.Euler(0, wheels[1].steerAngle, -FwheelCamber);
TranswheelMesh[2].transform.localRotation = Quaternion.Euler(0, wheels[2].steerAngle, RwheelCamber);
TranswheelMesh[3].transform.localRotation = Quaternion.Euler(0, wheels[3].steerAngle, -RwheelCamber);
//CamberFloat[i] =
//wheelMesh[i].transform.rotation = wheelRotation; // Quaternion.Euler(0, 0, wheelCamber);
wheelMesh[i].transform.Rotate(wheels[i].rpm * 6 * Time.deltaTime, 0, 0, Space.Self);
TranswheelMesh[i].transform.position = wheelPosition;
}
}
public void getObjects()
{
IM = Car.GetComponent<Input_Manager>();
rigidbody = Car.GetComponent<Rigidbody>();
//WC = GetComponent<wheelColliderFriction>();
//WB = Car.transform.Find("Wheels").gameObject;
wheelColliders = gameObject.transform.Find("wheelColliders").gameObject;
wheelMeshes = gameObject.transform.Find("wheelMeshes").gameObject;
TranswheelMesh[0] = wheelMeshes.transform.Find("MeshTransformFL").gameObject;
TranswheelMesh[1] = wheelMeshes.transform.Find("MeshTransformFR").gameObject;
TranswheelMesh[2] = wheelMeshes.transform.Find("MeshTransformRL").gameObject;
TranswheelMesh[3] = wheelMeshes.transform.Find("MeshTransformRR").gameObject;
wheels[0] = wheelColliders.transform.Find("FrontLeftWheel").gameObject.GetComponent<WheelCollider>();
wheels[1] = wheelColliders.transform.Find("FrontRightWheel").gameObject.GetComponent<WheelCollider>();
wheels[2] = wheelColliders.transform.Find("RearLeftWheel").gameObject.GetComponent<WheelCollider>();
wheels[3] = wheelColliders.transform.Find("RearRightWheel").gameObject.GetComponent<WheelCollider>();
wheelMesh[0] = TranswheelMesh[0].transform.Find("frontLeftWheel").gameObject;
wheelMesh[1] = TranswheelMesh[1].transform.Find("frontRightWheel").gameObject;
wheelMesh[2] = TranswheelMesh[2].transform.Find("rearLeftWheel").gameObject;
wheelMesh[3] = TranswheelMesh[3].transform.Find("rearRightWheel").gameObject;
}
private void addDownForce()
{
Vector3 XF = this.transform.InverseTransformDirection(rigidbody.velocity);
//Vector3 XL = XF * Time.deltaTime * 1000;
LOG = XF.z;
LOGY = XF.y;
rigidbody.AddForceAtPosition((rigidbody.angularDrag / 2) * -transform.up * Mathf.Pow(Vector3.Dot(rigidbody.velocity, transform.up), 2) * Mathf.Sign(LOGY), rigidbody.transform.position, ForceMode.Force);
rigidbody.AddForce(AreoForceValueCar * -transform.up * Mathf.Pow(Vector3.Dot(rigidbody.velocity, transform.up), 2) * Mathf.Sign(LOGY));
//rigidbody.AddForce(transform.up * 1500);
if (FrontForce)
{
//Vector3 Atach = FrontForce.position;
FrontWidth = FrontForce.transform.localScale.x;
FrontLenght = FrontForce.transform.localScale.z;
rigidbody.AddForceAtPosition((DownForceValue_Front * ((FrontWidth * FrontLenght / 2) / 100)) * -transform.up * Mathf.Pow(Vector3.Dot(rigidbody.velocity, transform.forward), 2) * Mathf.Sign(LOG), FrontForce.transform.position, ForceMode.Force);
}
if (RearForce)
{
//Vector3 Atach = RearForce.position;
RearWidth = RearForce.transform.localScale.x;
RearLenght = RearForce.transform.localScale.z;
//rigidbody.AddForceAtPosition(DownForceValue_Rear * transform.up * 1000, RearForce.position, ForceMode.Force);
rigidbody.AddForceAtPosition((DownForceValue_Rear * ((RearWidth * RearLenght / 2) / 100)) * -transform.up * Mathf.Pow(Vector3.Dot(rigidbody.velocity, transform.forward), 2) * Mathf.Sign(LOG), RearForce.transform.position, ForceMode.Force);
RAF = (DownForceValue_Rear * ((RearWidth * RearLenght / 2) / 100)) * Mathf.Pow(Vector3.Dot(rigidbody.velocity, transform.forward), 2) * Mathf.Sign(LOG);
}
for (int i = 0; i < DownForceValue_Other.Length; i++)
{
//Anchor.transform.position = OtherForce[1].transform.position;
if (OtherForce[i])
{
OtherWidth[i] = OtherForce[i].transform.localScale.x;
OtherLenght[i] = OtherForce[i].transform.localScale.z;
//Vector3 Atach = OtherForce[i].position;
rigidbody.AddForceAtPosition((-transform.up * (DownForceValue_Other[i] * ((OtherWidth[i] * OtherLenght[i] / 2) / 100))) * Mathf.Pow(Vector3.Dot(rigidbody.velocity, transform.forward), 2) * Mathf.Sign(LOG), OtherForce[i].transform.position, ForceMode.Force);
}
}
}
private void getFriction()
{
for (int i = 0; i < wheels.Length; i++)
{
WheelHit wheelHit;
wheels[i].GetGroundHit(out wheelHit);
Sslip[i] = wheelHit.sidewaysSlip;
Fslip[i] = wheelHit.forwardSlip;
WForce[i] = wheelHit.force;
//SuspensionSpring = wheels[i].suspensionSpring;
FLSpring = wheels[0].suspensionSpring;
FRSpring = wheels[1].suspensionSpring;
RLSpring = wheels[2].suspensionSpring;
RRSpring = wheels[3].suspensionSpring;
if (AntiRollBarsInUseFront)
{
FLDS = wheels[0].transform.InverseTransformPoint(wheelHit.point).y - wheels[0].radius / wheels[0].suspensionDistance;
FRDS = wheels[1].transform.InverseTransformPoint(wheelHit.point).y - wheels[1].radius / wheels[1].suspensionDistance;
FLSpring.spring = SpringForceFront + Mathf.Lerp(FrontARBForce, FrontARBForce * FLDS - FRDS, Time.deltaTime);
FRSpring.spring = SpringForceFront + Mathf.Lerp(FrontARBForce, FrontARBForce * FRDS - FLDS, Time.deltaTime);
}
else
{
FLSpring.spring = SpringForceFront;
FRSpring.spring = SpringForceFront;
}
//wheels[i].suspensionSpring = SuspensionSpring;
//SuspensionSpring = wheels[i].suspensionSpring;
if (AntiRollBarsInUseRear)
{
RLDS = wheels[2].transform.InverseTransformPoint(wheelHit.point).y - wheels[2].radius / wheels[2].suspensionDistance;
RRDS = wheels[3].transform.InverseTransformPoint(wheelHit.point).y - wheels[3].radius / wheels[3].suspensionDistance;
RLSpring.spring = SpringForceRear + Mathf.Lerp(RearARBForce, RearARBForce * RLDS - RRDS, Time.deltaTime);
RRSpring.spring = SpringForceRear + Mathf.Lerp(RearARBForce, RearARBForce * RRDS - RLDS, Time.deltaTime);
}
else
{
RLSpring.spring = SpringForceRear;
RRSpring.spring = SpringForceRear;
}
//wheels[i].suspensionSpring = SuspensionSpring;
wheels[0].suspensionSpring = FLSpring;
wheels[1].suspensionSpring = FRSpring;
wheels[2].suspensionSpring = RLSpring;
wheels[3].suspensionSpring = RRSpring;
if (wheels[i].isGrounded && !wheelHit.collider.CompareTag("Terrain"))
{
tireStifFBase[i] = tireStifF_Road - (TireSnowReductionA_F * SnowValue) - (TireRainReductionA_F * RainValue);
tireStifSBase[i] = tireStifS_Road - (TireSnowReductionA_S * SnowValue) - (TireRainReductionA_S * RainValue);
}
else if (wheels[i].isGrounded && wheelHit.collider.CompareTag("Terrain"))
{
tireStifFBase[i] = tireStifF_Gravel - (TireSnowReductionG_F * SnowValue) - (TireRainReductionG_F * RainValue);
tireStifSBase[i] = tireStifS_Gravel - (TireSnowReductionG_S * SnowValue) - (TireRainReductionG_S * RainValue);
}
}
}
[BurstCompile]
public struct TireTestJob : IJobParallelFor
{
public NativeArray<float> JobStiffnesPowerCDS;
public NativeArray<float> JobStiffnesPowerCDF;
public NativeArray<float> JobSidewaysFEA;
public NativeArray<float> JobForwardFEA;
public NativeArray<float> JobSidewaysSEA;
public NativeArray<float> JobForwardSEA;
[ReadOnly] public NativeArray<float> FslipValue;
[ReadOnly] public NativeArray<float> SslipValue;
public NativeArray<float> WForceValue;
public NativeArray<float> StifBaseS;
public NativeArray<float> StifBaseF;
public NativeArray<float> JobFlexForce;
public NativeArray<float> JobFlexForce1;
public NativeArray<float> JobFlexForceFinish;
public NativeArray<float> JobFlexForce1Finish;
public NativeArray<float> SRLValueJob;
public NativeArray<float> JobCGFCV;
public NativeArray<float> JobCGFCVD;
public NativeArray<float> JobFCGFCV;
public NativeArray<float> JobFCGFCVD;
public NativeArray<float> JobCWF;
public NativeArray<float> JobwheelWidth;
public NativeArray<float> JobtireRadio;
public NativeArray<float> JobSlipRadio;
public NativeArray<float> JobSlipRadioFinish;
public NativeArray<float> JobTireHardnes;
public NativeArray<float> JobTranswheelMeshValue;
public NativeArray<float> SlipTD;
public NativeArray<float> SlipR;
public NativeArray<float> JobSetrpm;
public NativeArray<float> SSCVJobFinish;
public NativeArray<float> FSCVJobFinish;
public NativeArray<float> SACVJobFinish;
public NativeArray<float> FSACVJobFinish;
public NativeArray<float> SSCVJob;
public NativeArray<float> FSCVJob;
public NativeArray<float> SACVJob;
public NativeArray<float> FSACVJob;
public NativeArray<float> JobforceAppPointDistance;
public float JobSSF;
public float JobFSF;
public float JobKPH;
public float Jobcg;
/*
SSCVJob;
FSCVJob;
SACVJob;
FSACVJob;
*/
public void Execute(int IndexWheel)
{
SlipTD[IndexWheel] = Mathf.Abs(FslipValue[IndexWheel]) + Mathf.Abs(SslipValue[IndexWheel] / 1.5f);
SlipR[IndexWheel] = Mathf.Abs(FslipValue[IndexWheel]);
JobFlexForce[IndexWheel] = (WForceValue[IndexWheel] * ((Math.Clamp(JobwheelWidth[IndexWheel] * 2, 0.1f, 0.65f)) + (JobtireRadio[IndexWheel] * 1) / (JobTireHardnes[IndexWheel])));
JobCGFCV[IndexWheel] = Math.Abs((JobTranswheelMeshValue[IndexWheel] / 100) * Math.Sign(JobCWF[IndexWheel])) + Math.Abs(SslipValue[IndexWheel]);
JobFCGFCV[IndexWheel] = Math.Abs((JobTranswheelMeshValue[IndexWheel] / 100) * Math.Sign(JobCWF[IndexWheel])) + Math.Abs(SslipValue[IndexWheel]);
SRLValueJob[IndexWheel] = Math.Clamp(JobSSF * Math.Clamp((Math.Abs(SslipValue[IndexWheel] * 1.25f) + Math.Clamp(Math.Abs((FslipValue[IndexWheel] * 1)) - Math.Abs(SslipValue[IndexWheel] * 2), 0, 2f)) * 1, 0.5f, 2f) - 0.5f, 0.75f, 10);
SSCVJob[IndexWheel] = (/*wheelSidewaysValueGrip.Evaluate*/(SlipTD[IndexWheel] + Math.Clamp(Math.Abs(SslipValue[IndexWheel]), 0, 0.1f + (JobtireRadio[IndexWheel] / 2 * (JobTireHardnes[IndexWheel] / 3)))) * 4);
SACVJob[IndexWheel] = ((Math.Abs(SlipTD[IndexWheel] + Math.Clamp(Math.Abs(SslipValue[IndexWheel]), -0.5f, 0.5f))) * (JobtireRadio[IndexWheel] + 2f));
FSCVJob[IndexWheel] = SlipTD[IndexWheel];
FSACVJob[IndexWheel] = (Math.Abs(SlipTD[IndexWheel] * Math.Clamp(1.5f - (JobtireRadio[IndexWheel] / 2), 1f, 1.25f)));
JobFlexForce1[IndexWheel] = (WForceValue[IndexWheel] * ((Math.Clamp(JobwheelWidth[IndexWheel], 0.2f, 0.5f) * 2) + (JobFSF * Math.Abs(SslipValue[IndexWheel] * (float)(Math.Pow(Math.Abs(FslipValue[IndexWheel]) * 1.5f, 1.5f)) * Math.Clamp(1 - (JobtireRadio[IndexWheel] * 10), 0.1f, 1) * (JobwheelWidth[IndexWheel] * 4))) + (JobtireRadio[IndexWheel] * 4) / JobTireHardnes[IndexWheel]));
JobStiffnesPowerCDS[IndexWheel] = Math.Clamp(StifBaseS[IndexWheel] * ((JobFlexForceFinish[IndexWheel] / SRLValueJob[IndexWheel]) * JobCGFCVD[IndexWheel]) + Jobcg, 0, 2.5f * (1 * Math.Clamp(JobKPH / 30, 1, 4f)));
JobSidewaysFEA[IndexWheel] = (SSCVJobFinish[IndexWheel] * (Math.Clamp(JobwheelWidth[IndexWheel], 0.01f, 0.3f) * 2 / (float)(1f + Math.Sqrt(Math.Clamp(JobtireRadio[IndexWheel] * 2, 1, 999999f)) / 20)) - Math.Clamp(Math.Abs(Math.Clamp(JobSetrpm[IndexWheel], 0f, 10000 / (-JobTireHardnes[IndexWheel])) / 10000) * (-JobTireHardnes[IndexWheel]) * ((JobtireRadio[IndexWheel] * 10) + (JobwheelWidth[IndexWheel] * 10)), 0f, JobtireRadio[IndexWheel] * 2));
JobSidewaysSEA[IndexWheel] = SACVJobFinish[IndexWheel] * (((2f - Math.Clamp(JobtireRadio[IndexWheel] * 1, 0.1f, 0.75f)) * (0.5f + Math.Abs(FslipValue[IndexWheel]))));
JobforceAppPointDistance[IndexWheel] = (float)((Math.Sqrt(StifBaseF[IndexWheel] * 1) * Math.Clamp(Math.Abs((FslipValue[IndexWheel] * (1 - Math.Clamp(10 * Math.Abs(SslipValue[IndexWheel]), 0, 1))) * Math.Clamp(JobSetrpm[IndexWheel], 0.25f, 1) * ((Math.Sqrt(Math.Clamp(StifBaseS[IndexWheel], 0, 2)) * 1)) / (1 + 9 * Math.Abs(SslipValue[IndexWheel]))), 0, 0.5f)) - Math.Clamp(Math.Abs(SslipValue[IndexWheel] / 5f) * ((Math.Pow(JobtireRadio[IndexWheel] + JobSetrpm[IndexWheel], 2) * 2)) * 2 * (Math.Clamp(JobSetrpm[IndexWheel], 0.25f, 1)), 0, 0.025f));
JobStiffnesPowerCDF[IndexWheel] = Math.Clamp(StifBaseF[IndexWheel] * (((JobFlexForce1Finish[IndexWheel] * Math.Clamp(1.5f - Math.Abs(FslipValue[IndexWheel]), 0.05f, 0.75f))) * JobFCGFCVD[IndexWheel]) + Jobcg, 0, 2.5f * (1 * Math.Clamp(JobKPH / 30, 1, 4f)));
JobForwardFEA[IndexWheel] = (FSCVJobFinish[IndexWheel] * 4) * (((Math.Clamp(JobwheelWidth[IndexWheel], 0.1f, 0.5f) / 2) + (JobtireRadio[IndexWheel] * Math.Clamp(2f * Math.Abs(FslipValue[IndexWheel]), 1, 2)) * 1) * 1) + Math.Clamp(Math.Abs(Math.Clamp(JobSetrpm[IndexWheel], 0f, 10000 / (-JobTireHardnes[IndexWheel])) / 10000) * (-JobTireHardnes[IndexWheel]) * ((JobtireRadio[IndexWheel]) + (JobwheelWidth[IndexWheel] * 10)), 0f, JobtireRadio[IndexWheel] * 10);
JobForwardSEA[IndexWheel] = (FSACVJobFinish[IndexWheel]) * (((JobtireRadio[IndexWheel] / 2) / (JobwheelWidth[IndexWheel] / 2)) / 1.25f) * ((JobSlipRadioFinish[IndexWheel] * (2 / Math.Clamp(JobtireRadio[IndexWheel], 1, 99999999999))) / Math.Clamp(Math.Abs(JobSetrpm[IndexWheel]), 0.5f, 1));
}
}
private void OnDestroy()
{
if (StiffnesPowerCDS.IsCreated)
{
StiffnesPowerCDS.Dispose();
StiffnesPowerCDF.Dispose();
FlexForce.Dispose();
FlexForceDone.Dispose();
FlexForce1.Dispose();
FlexForce1Done.Dispose();
SlipRadioJ.Dispose();
SlipRadioJDone.Dispose();
SRLValue.Dispose();
FslipVF.Dispose();
SslipVF.Dispose();
WForceVF.Dispose();
JobtireFtifFBase.Dispose();
JobtireStifSBase.Dispose();
DJobCWF.Dispose();
DJobCGFCV.Dispose();
DJobCGFCVD.Dispose();
DJobFCGFCV.Dispose();
DJobFCGFCVD.Dispose();
DSSCVJob.Dispose();
DSSCVJobFinish.Dispose();
DFSCVJob.Dispose();
DFSCVJobFinish.Dispose();
DSACVJob.Dispose();
DSACVJobFinish.Dispose();
DFSACVJob.Dispose();
DFSACVJobFinish.Dispose();
DJobwheelWidth.Dispose();
DJobtireRadio.Dispose();
DJobTireHardnes.Dispose();
DJobTranswheelMeshValue.Dispose();
JobforceAppPointDistanceSet.Dispose();
SG.Dispose();
SS.Dispose();
FG.Dispose();
FS.Dispose();
S2D.Dispose();
SRJ.Dispose();
RPMJ.Dispose();
}
}
}