void Start() { myTransform = transform; body = rigidbody; if (meshFilters.Length == 0) { //meshFilters = GetComponentsInChildren<MeshFilter>(); m_meshFilters = GetComponentsInChildren <MeshFilter>(); int k = 0; for (i = 0; i < m_meshFilters.Length; i++) { if (m_meshFilters[i].collider == null) { k++; } } meshFilters = new MeshFilter[k]; k = 0; for (i = 0; i < m_meshFilters.Length; i++) { if (m_meshFilters[i].collider == null) { meshFilters[k] = m_meshFilters[i]; k++; } } } if (meshCollider != null) { //meshFilterColl=meshCollider.gameObject.GetComponent<MeshFilter>(); colliderVerts = meshCollider.sharedMesh.vertices; } LoadoriginalMeshData(); foreach (Transform child in transform) { if (child.gameObject.tag == "Body" || child.gameObject.name == "Body" || child.gameObject.name == "body") { GObody = child.gameObject; } } if (GObody) { sign = Mathf.Cos(GObody.transform.localEulerAngles.y * Mathf.Deg2Rad); if (GObody.transform.localEulerAngles.x != 0) { rot = Quaternion.AngleAxis(GObody.transform.localEulerAngles.x * 3, Vector3.right); } } carDynamics = GetComponent <CarDynamics>(); axles = GetComponent <Axles>(); wheelLayer = axles.allWheels[0].transform.gameObject.layer; carLayer = transform.gameObject.layer; }
protected virtual void Start() { body = rigidbody; cardynamics = GetComponent <CarDynamics>(); drivetrain = GetComponent <Drivetrain>(); axles = GetComponent <Axles>(); allWheels = axles.allWheels; myTransform = transform; }
void Start() { body = GetComponent <Rigidbody>(); cardynamics = GetComponent <CarDynamics>(); drivetrain = GetComponent <Drivetrain>(); axles = GetComponent <Axles>(); allWheels = axles.allWheels; myTransform = transform; }
void Start(){ body=rigidbody; carDynamics = GetComponent<CarDynamics>(); axles = GetComponent<Axles>(); if (overallStrength<0) overallStrength=0; if (COGHelperStrength<0) COGHelperStrength=0; if (torqueHelperStrength<0) torqueHelperStrength=0; if (gripHelperStrength<0) gripHelperStrength=0; }
void Start() { //soundVolume = GameObject.Find("SoundVolume").GetComponent<UISlider>(); selectCarController = GameObject.Find("Controller").GetComponent <SelectCarController>(); carController = GetComponent <CarController>(); cardynamics = GetComponent <CarDynamics>(); drivetrain = GetComponent <Drivetrain>(); physicMaterials = GetComponent <PhysicMaterials>(); axles = GetComponent <Axles>(); Vector3 enginePositionV = Vector3.zero; if (enginePosition != null) { enginePositionV = enginePosition.transform.position; } engineThrottleSource = CreateAudioSource(engineThrottle, true, true, enginePositionV); engineNoThrottleSource = CreateAudioSource(engineNoThrottle, true, true, enginePositionV); transmissionSource = CreateAudioSource(transmission, true, true, Vector3.zero); brakeNoiseSource = CreateAudioSource(brakeNoise, true, true, Vector3.zero); startEngineSource = CreateAudioSource(startEngine, true, false, enginePositionV); startEngineSource.volume = startEngineVolume * selectCarController.VolumeEffects;//b startEngineSource.pitch = startEnginePitch; System.Array.Resize(ref skidSource, axles.allWheels.Length); i = 0; foreach (Wheel w in axles.allWheels) { skidSource[i] = CreateAudioSource(skid, true, true, w.transform.localPosition); i++; } crashHiSpeedSource = CreateAudioSource(crashHiSpeed, false, false, Vector3.zero); crashLowSpeedSource = CreateAudioSource(crashLowSpeed, false, false, Vector3.zero); scrapeNoiseSource = CreateAudioSource(scrapeNoise, false, false, Vector3.zero); ABSTriggerSource = CreateAudioSource(ABSTrigger, false, false, Vector3.zero); ABSTriggerSource.volume = ABSTriggerVolume; shiftTriggerSource = CreateAudioSource(shiftTrigger, false, false, Vector3.zero); shiftTriggerSource.volume = shiftTriggerVolume; windSource = CreateAudioSource(wind, true, true, Vector3.zero); if (physicMaterials) { System.Array.Resize(ref rollingNoiseSource, axles.allWheels.Length); i = 0; foreach (Wheel w in axles.allWheels) { rollingNoiseSource[i] = CreateAudioSource(rollingNoiseGrass, true, false, w.transform.localPosition); i++; } } }
void Awake() { engineTorqueFromFile = false; torqueRPMValuesLen = 0; body = rigidbody; myTransform = transform; clutch = new Clutch(); carController = GetComponent <CarController>(); setup = GetComponent <Setup>(); axles = GetComponent <Axles>(); fuelTanks = GetComponentsInChildren <FuelTank>(); poweredWheels = axles.rearAxle.wheels; // to avoid NullReferenceException }
void Start() { if (brakeLights == null) { brakeLights = GetComponent <BrakeLights>(); } if (drivetrain == null) { drivetrain = GetComponent <Drivetrain>(); } if (aerodynamicResistance == null) { aerodynamicResistance = GetComponent <AerodynamicResistance>(); } if (soundController == null) { soundController = GetComponent <SoundController>(); } if (carDynamics == null) { carDynamics = GetComponent <CarDynamics>(); } if (axles == null) { axles = GetComponent <Axles>(); } if (axisCarController == null) { axisCarController = GetComponent <AxisCarController>(); } if (carDamage == null) { carDamage = GetComponent <CarDamage>(); } if (arcader == null) { arcader = GetComponent <Arcader>(); } if (setup == null) { setup = GetComponent <Setup>(); } if (bodyRb == null) { bodyRb = GetComponent <Rigidbody>(); } if (camerasController == null) { camerasController = GetComponent <CamerasController>(); } }
void SetComponent(){ drivetrain = GetComponent<Drivetrain>(); cardynamics = GetComponent<CarDynamics>(); forceFeedback= GetComponent<ForceFeedback>(); physicMaterials =GetComponent<PhysicMaterials>(); arcader= GetComponent<Arcader>(); aerodynamicResistance= GetComponent<AerodynamicResistance>(); axles= GetComponent<Axles>(); axisCarController = GetComponent <AxisCarController>(); mouseCarController = GetComponent <MouseCarController>(); mobileCarController = GetComponent <MobileCarController>(); fuelTanks=GetComponentsInChildren<FuelTank>(); wings=GetComponentsInChildren<Wing>(); }
private void ResetTunning() { CameraTarget tractor = character.GetComponentInChildren <CameraTarget>(); Drivetrain drivetrain = tractor.GetComponent <Drivetrain>(); drivetrain.maxPower = enemyCar[currentCar].MaxPower; drivetrain.maxTorque = enemyCar[currentCar].MaxTorque; Axles axles = tractor.GetComponent <Axles>(); axles.frontAxle.sidewaysGripFactor = enemyCar[currentCar].Sideways; axles.rearAxle.sidewaysGripFactor = enemyCar[currentCar].Sideways; axles.frontAxle.brakeFrictionTorque = enemyCar[currentCar].Brake; axles.rearAxle.brakeFrictionTorque = enemyCar[currentCar].Brake; foreach (Axle axle in axles.otherAxles) { axle.sidewaysGripFactor = enemyCar[currentCar].Sideways; axle.brakeFrictionTorque = enemyCar[currentCar].Brake; } //tractor.GetComponent<Setup>().SaveSetup(); maxSpeedIndicator.text = enemyCar[currentCar].MaxSpeed.ToString("f0"); }
void Start() { body = rigidbody; carDynamics = GetComponent <CarDynamics>(); axles = GetComponent <Axles>(); if (overallStrength < 0) { overallStrength = 0; } if (COGHelperStrength < 0) { COGHelperStrength = 0; } if (torqueHelperStrength < 0) { torqueHelperStrength = 0; } if (gripHelperStrength < 0) { gripHelperStrength = 0; } }
void Awake() { body = GetComponent <Rigidbody>(); originalCenterOfMass = body.centerOfMass; myTransform = transform; drivetrain = GetComponent <Drivetrain>(); axisCarController = GetComponent <AxisCarController>(); mouseCarcontroller = GetComponent <MouseCarController>(); mobileCarController = GetComponent <MobileCarController>(); brakeLights = GetComponent <BrakeLights>(); dashBoard = myTransform.GetComponentInChildren <DashBoard>(); steeringWheel = transform.GetComponentInChildren <SteeringWheel>(); soundController = GetComponent <SoundController>(); SetController(controller.ToString()); axles = GetComponent <Axles>(); //frontWheels=axles.frontAxle.wheels; //rearWheels=axles.rearAxle.wheels; //otherWheels=axles.otherWheels; //axles.allWheels=axles.axles.allWheels; invAllWheelsLength = 1f / axles.allWheels.Length; fixedTimeStepScalar = 0.02f / Time.fixedDeltaTime; invFixedTimeStepScalar = 1 / fixedTimeStepScalar; }
public IEnumerator ChangeCar(GameObject mselectedCar){ if(mselectedCar!=null){ mTransform=mselectedCar.transform; mrigidbody = mselectedCar.GetComponent<Rigidbody>(); carDynamics = mselectedCar.GetComponent<CarDynamics>(); drivetrain = mselectedCar.GetComponent<Drivetrain>(); aerodynamicResistance = mselectedCar.GetComponent<AerodynamicResistance>(); carDebug = mTransform.GetComponent<CarDebug>(); carDamage = mselectedCar.GetComponent<CarDamage>(); carController = mselectedCar.GetComponent<CarDynamics>().carController; dashBoard=mselectedCar.transform.GetComponentInChildren<DashBoard>(); arcader=mselectedCar.transform.GetComponentInChildren<Arcader>(); setup= mselectedCar.GetComponent<Setup>(); axles=mselectedCar.GetComponent<Axles>(); fuelTanks=mselectedCar.GetComponentsInChildren<FuelTank>(); currentFuels=new float[fuelTanks.Length]; if (setup!=null && setup.enabled==true) {while (setup.loadingSetup==true) yield return new WaitForSeconds(0.02f);} if (drivetrain.engineTorqueFromFile==true) drivetrain.CalcValues(factor,drivetrain.engineTorqueFromFile); drivetrain.engineTorqueFromFile=false; if (Application.isEditor && setup!=null && setup.enabled==true){ GridEntrys = new string[] {"Engine", "Transmission", "Suspensions", "Brakes" ,"Tires", "Body", "Assistance","Save Setup"}; entrysCount=8; } else{ GridEntrys = new string[] {"Engine", "Transmission", "Suspensions", "Brakes" ,"Tires", "Body", "Assistance"}; entrysCount=7; } if (arcader) arcader.enabled=false; m_maxTorque=drivetrain.maxTorque; //ESP=carController.ESP; selectedCar=mselectedCar; //carDynamics.SetTiresType(); tiresTypeFront=(int)axles.frontAxle.tires; tiresTypeRear=(int)axles.rearAxle.tires; //drivetrain.SetTransmission(drivetrain.transmission); transmissionType=oldTransmissionType=(int)drivetrain.transmission; //SetCOGPosition(carDynamics.zlocalPosition); boundingSize=carDynamics.BoundingSize(selectedCar.GetComponentsInChildren<Collider>()); zlocalPositionLimit=0.8f*boundingSize.x/4.5f; engageRPM=drivetrain.engageRPM; maxRPM=(Mathf.CeilToInt(drivetrain.maxRPM/1000)+1)*1000; maxKmh=Mathf.RoundToInt(maxRPM*axles.frontAxle.leftWheel.radius*2*0.1885f/(drivetrain.gearRatios[drivetrain.gearRatios.Length-1]*drivetrain.finalDriveRatio)); // Mathf.PI*3.6f/60 -> 0.1885 mass=mrigidbody.mass; StartSize = new Vector2(Screen.width, Screen.height); if (grid!=null) floor=(grid.height - gridHeight)/2; top=gridHeight+Mathf.RoundToInt(gridHeight*0.17f)+floor; RectCalculation(StartSize); ScrollRectCalculation(StartSize, drivetrain.gearRatios.Length-2); factor=1; if (grid!=null){ switch(GridInt) { case 0: ApplyEngineTorque();break; case 1: ApplyGears();break; } } } }
void Start(){ myTransform=transform; trs = myTransform.parent; while (trs != null && trs.rigidbody == null) trs = trs.parent; if (trs != null) body = trs.rigidbody; trs = myTransform.parent; while (trs.GetComponent<PhysicMaterials>() == null) {if (trs.parent) trs = trs.parent; else break;} physicMaterials = trs.GetComponent<PhysicMaterials>(); trs = myTransform.parent; while (trs.GetComponent<CarDynamics>() == null) trs = trs.parent; cardynamics = trs.GetComponent<CarDynamics>(); drivetrain = trs.GetComponent<Drivetrain>(); axles = trs.GetComponent<Axles>(); localScale=1/(trs.localScale.y*myTransform.localScale.y); layerMask=1<<trs.gameObject.layer | 1<<myTransform.gameObject.layer;//LayerMask.NameToLayer("Wheel"); layerMask=~layerMask; radiusLoaded=radius; if (rimRadius==0) rimRadius=radius*0.735f; sidewallHeight=radius - rimRadius; if (mass<50*cardynamics.invFixedTimeStepScalar) mass=50*cardynamics.invFixedTimeStepScalar; if (rotationalInertia==0 || rotationalInertia<(mass/2)*radius*radius) rotationalInertia=(mass/2)*radius*radius; originalMass=mass; if (model==null) { model = new GameObject("temp_model"); model.transform.parent=transform; model.transform.localPosition=new Vector3(0,0,0); model.transform.localRotation=Quaternion.identity; Debug.LogWarning("UnityCar: wheel model in " + wheelPos + " is missing. Using empty object" + " (" +trs.name+ ")"); } modelTransform=model.transform; if (caliperModel!=null) caliperModelTransform=caliperModel.transform; skidmarks = cardynamics.skidmarks; if (skidmarks) skidSmoke = skidmarks.GetComponentInChildren(typeof(ParticleEmitter)) as ParticleEmitter; suspensionLineRenderer=gameObject.GetComponent<LineRenderer>(); if (suspensionLineRenderer==null) suspensionLineRenderer = gameObject.AddComponent<LineRenderer>(); suspensionLineRenderer.material = new Material(Shader.Find("Diffuse")); suspensionLineRenderer.material.color = Color.yellow; suspensionLineRenderer.SetWidth(0.01f,0.1f); suspensionLineRenderer.useWorldSpace = false; suspensionLineRenderer.castShadows = false; camber*=1; // to avoid never assigned warning if (camber==0){ up = myTransform.up; } else{ camberRotation = Quaternion.AngleAxis(-camber,forwardNormal); up = camberRotation*myTransform.up; } SetTireStiffness(); }
void Awake(){ body=rigidbody; originalCenterOfMass=body.centerOfMass; myTransform=transform; drivetrain= GetComponent<Drivetrain>(); axisCarController = GetComponent <AxisCarController>(); mouseCarcontroller = GetComponent <MouseCarController>(); mobileCarController = GetComponent <MobileCarController>(); brakeLights=GetComponent <BrakeLights>(); dashBoard = myTransform.GetComponentInChildren <DashBoard>(); steeringWheel = transform.GetComponentInChildren <SteeringWheel>(); soundController=GetComponent<SoundController>(); SetController(controller.ToString()); axles=GetComponent<Axles>(); //frontWheels=axles.frontAxle.wheels; //rearWheels=axles.rearAxle.wheels; //otherWheels=axles.otherWheels; //axles.allWheels=axles.axles.allWheels; invAllWheelsLength=1f/axles.allWheels.Length; fixedTimeStepScalar=0.02f/Time.fixedDeltaTime; invFixedTimeStepScalar=1/fixedTimeStepScalar; }
void Start () { carController = GetComponent<CarController>(); cardynamics = GetComponent<CarDynamics>(); drivetrain= GetComponent<Drivetrain>(); physicMaterials =GetComponent<PhysicMaterials>(); axles=GetComponent<Axles>(); Vector3 enginePositionV=Vector3.zero; if (enginePosition!=null) enginePositionV=enginePosition.transform.position; engineThrottleSource = CreateAudioSource(engineThrottle, true, true,enginePositionV); engineNoThrottleSource = CreateAudioSource(engineNoThrottle, true, true,enginePositionV); transmissionSource = CreateAudioSource(transmission, true, true,Vector3.zero); brakeNoiseSource = CreateAudioSource(brakeNoise, true, true,Vector3.zero); startEngineSource= CreateAudioSource(startEngine, true, false,enginePositionV); startEngineSource.volume=startEngineVolume; startEngineSource.pitch=startEnginePitch; System.Array.Resize(ref skidSource,axles.allWheels.Length); i=0; foreach(Wheel w in axles.allWheels){ skidSource[i] = CreateAudioSource(skid, true, true,w.transform.localPosition); i++; } crashHiSpeedSource = CreateAudioSource(crashHiSpeed, false, false,Vector3.zero); crashLowSpeedSource = CreateAudioSource(crashLowSpeed, false, false,Vector3.zero); scrapeNoiseSource = CreateAudioSource(scrapeNoise, false, false,Vector3.zero); ABSTriggerSource= CreateAudioSource(ABSTrigger, false, false,Vector3.zero); ABSTriggerSource.volume=ABSTriggerVolume; shiftTriggerSource= CreateAudioSource(shiftTrigger, false, false,Vector3.zero); shiftTriggerSource.volume=shiftTriggerVolume; windSource = CreateAudioSource(wind, true, true,Vector3.zero); if (physicMaterials){ System.Array.Resize(ref rollingNoiseSource,axles.allWheels.Length); i=0; foreach(Wheel w in axles.allWheels){ rollingNoiseSource[i]=CreateAudioSource(rollingNoiseGrass, true, false,w.transform.localPosition); i++; } } }
/// <summary> /// Initialize class /// </summary> /// <param name="gameObjectName"></param> public Vehicle(string gameObjectName) { // gameObject the object by name gameObject = GameObject.Find(gameObjectName); // Use Resources.FindObjectsOfTypeAll method, if the vehicle was not found. if (gameObject == null) { gameObject = Resources.FindObjectsOfTypeAll <GameObject>().FirstOrDefault(g => g.name == gameObjectName); } if (gameObject == null) { ModConsole.Error($"[MOP] Could not find {gameObjectName} vehicle."); return; } // Get the object position and rotation Position = gameObject.transform.localPosition; Rotation = gameObject.transform.localRotation; // Creates a new gameobject that is names after the original file + '_TEMP' (ex. "SATSUMA(557kg, 248)_TEMP") temporaryParent = new GameObject($"{gameObject.name}_TEMP").transform; preventToggleOnObjects = new List <PreventToggleOnObject>(); // This should fix bug that leads to items inside of vehicles to fall through it. PlayMakerFSM lodFSM = gameObject.GetPlayMakerByName("LOD"); if (lodFSM != null) { lodFSM.Fsm.RestartOnEnable = false; FsmState resetState = lodFSM.FindFsmState("Fix Collider"); if (resetState != null) { resetState.Actions = new FsmStateAction[] { new CustomStopAction() }; resetState.SaveActions(); } lodFSM.FindFsmState("Load game").Actions = new FsmStateAction[] { new CustomNullState() }; } if (gameObject.name == "BOAT") { return; } // Get the object's child which are responsible for audio foreach (Transform audioObject in FindAudioObjects()) { preventToggleOnObjects.Add(new PreventToggleOnObject(audioObject)); } // Fix for fuel level resetting after respawn Transform fuelTank = gameObject.transform.Find("FuelTank"); if (fuelTank != null) { PlayMakerFSM fuelTankFSM = fuelTank.GetComponent <PlayMakerFSM>(); if (fuelTankFSM) { fuelTankFSM.Fsm.RestartOnEnable = false; } } // If the vehicle is Gifu, find knobs and add them to list of unloadable objects if (gameObject.name == "GIFU(750/450psi)") { Transform knobs = gameObject.transform.Find("Dashboard/Knobs"); foreach (PlayMakerFSM knobsFSMs in knobs.GetComponentsInChildren <PlayMakerFSM>()) { knobsFSMs.Fsm.RestartOnEnable = false; } PlayMakerFSM shitFsm = gameObject.transform.Find("ShitTank").gameObject.GetComponent <PlayMakerFSM>(); FsmState loadGame = shitFsm.FindFsmState("Load game"); List <FsmStateAction> loadArrayActions = new List <FsmStateAction> { new CustomNullState() }; loadArrayActions.Add(new CustomNullState()); loadGame.Actions = loadArrayActions.ToArray(); loadGame.SaveActions(); } // Fixed kickstand resetting to the default value. if (gameObject.name == "JONNEZ ES(Clone)") { PlayMakerFSM kickstandFsm = gameObject.transform.Find("Kickstand").gameObject.GetComponent <PlayMakerFSM>(); FsmState loadGame = kickstandFsm.FindFsmState("Load game"); List <FsmStateAction> loadArrayActions = new List <FsmStateAction> { new CustomNullState() }; loadArrayActions.Add(new CustomNullState()); loadGame.Actions = loadArrayActions.ToArray(); loadGame.SaveActions(); // Disable on restart for wheels script. Transform wheelsParent = transform.Find("Wheels"); foreach (Transform wheel in wheelsParent.GetComponentsInChildren <Transform>()) { if (!wheel.gameObject.name.StartsWith("Moped_wheel")) { continue; } wheel.gameObject.GetComponent <PlayMakerFSM>().Fsm.RestartOnEnable = false; } } carDynamics = gameObject.GetComponent <CarDynamics>(); axles = gameObject.GetComponent <Axles>(); rb = gameObject.GetComponent <Rigidbody>(); // Hook HookFront and HookRear // Get hooks first Transform hookFront = transform.Find("HookFront"); Transform hookRear = transform.Find("HookRear"); // If hooks exists, attach the RopeHookUp and RopeUnhook to appropriate states if (hookFront != null) { fsmHookFront = hookFront.GetComponent <PlayMakerFSM>(); } if (hookRear != null) { fsmHookRear = hookRear.GetComponent <PlayMakerFSM>(); } // If vehicle is flatbed, hook SwitchToggleMethod to Add scale script if (gameObject.name == "FLATBED") { PlayMakerFSM logTriggerFsm = transform.Find("Bed/LogTrigger").gameObject.GetComponent <PlayMakerFSM>(); FsmState loadGame = logTriggerFsm.FindFsmState("Load game"); List <FsmStateAction> loadArrayActions = new List <FsmStateAction> { new CustomNullState() }; loadGame.Actions = loadArrayActions.ToArray(); loadGame.SaveActions(); GameObject trailerLogUnderFloorCheck = new GameObject("MOP_TrailerLogUnderFloorFix"); trailerLogUnderFloorCheck.transform.parent = gameObject.transform; trailerLogUnderFloorCheck.AddComponent <TrailerLogUnderFloor>(); } // Set default toggling method - that is entire vehicle Toggle = ToggleActive; isHayosiko = gameObject.name == "HAYOSIKO(1500kg, 250)"; isKekmet = gameObject.name == "KEKMET(350-400psi)"; // If the user selected to toggle vehicle's physics only, it overrided any previous set for Toggle method if (Rules.instance.SpecialRules.ToggleAllVehiclesPhysicsOnly) { Toggle = IgnoreToggle; } // Get all HingeJoints and add HingeManager to them // Ignore for Satsuma or cars that use ToggleUnityCar method (and force for Hayosiko - no matter what) if (SatsumaScript == null && Toggle != ToggleUnityCar || isHayosiko) { HingeJoint[] joints = gameObject.transform.GetComponentsInChildren <HingeJoint>(); foreach (HingeJoint joint in joints) { joint.gameObject.AddComponent <HingeManager>(); } } // Get one of the wheels. wheel = axles.allWheels[0]; drivetrain = gameObject.GetComponent <Drivetrain>(); // Ignore Rules. IgnoreRule vehicleRule = Rules.instance.IgnoreRules.Find(v => v.ObjectName == this.gameObject.name); if (vehicleRule != null) { Toggle = IgnoreToggle; if (vehicleRule.TotalIgnore) { IsActive = false; } } // Prevent Toggle On Object Rule. IgnoreRuleAtPlace[] preventToggleOnObjectRule = Rules.instance.IgnoreRulesAtPlaces .Where(v => v.Place == this.gameObject.name).ToArray(); if (preventToggleOnObjectRule.Length > 0) { foreach (var p in preventToggleOnObjectRule) { Transform t = transform.FindRecursive(p.ObjectName); if (t == null) { ModConsole.Error($"[MOP] Couldn't find {p.ObjectName} in {p.Place}."); continue; } preventToggleOnObjects.Add(new PreventToggleOnObject(t)); } } eventSounds = gameObject.GetComponent <EventSounds>(); // Odometers fix. switch (gameObject.name) { case "GIFU(750/450psi)": transform.Find("Dashboard/Odometer").gameObject.GetComponent <PlayMakerFSM>().Fsm.RestartOnEnable = false; break; case "HAYOSIKO(1500kg, 250)": transform.Find("Odometer").gameObject.GetComponent <PlayMakerFSM>().Fsm.RestartOnEnable = false; break; case "KEKMET(350-400psi)": transform.Find("Dashboard/HourMeter").gameObject.GetComponent <PlayMakerFSM>().Fsm.RestartOnEnable = false; break; case "SATSUMA(557kg, 248)": GameObject.Find("dashboard meters(Clone)").transform.Find("Gauges/Odometer").gameObject.GetComponent <PlayMakerFSM>().Fsm.RestartOnEnable = false; break; } }
//[MenuItem("GameObject/Create Other/UnityCar")] public static GameObject CreateNewCar(){ Debug.LogWarning("Create new car"); GameObject unityCarObj=new GameObject("UnityCar"); if (unityCarObj.rigidbody==null){ mrigidbody=unityCarObj.AddComponent<Rigidbody>() as Rigidbody; mrigidbody.mass=1000; mrigidbody.angularDrag=0; mrigidbody.interpolation=RigidbodyInterpolation.Interpolate; } else mrigidbody=unityCarObj.GetComponent<Rigidbody>(); if (unityCarObj.GetComponent<CarDynamics>()==null) carDynamics=unityCarObj.AddComponent<CarDynamics>() as CarDynamics; else carDynamics=unityCarObj.GetComponent<CarDynamics>(); centerOfMassObject=new GameObject("COG"); centerOfMassObject.transform.parent=unityCarObj.transform; centerOfMassObject.transform.localPosition=Vector3.zero; centerOfMassObject.transform.localRotation=Quaternion.identity; carDynamics.centerOfMass=centerOfMassObject.transform; if (unityCarObj.GetComponent<Drivetrain>()==null) drivetrain =unityCarObj.AddComponent<Drivetrain>() as Drivetrain; else drivetrain=unityCarObj.GetComponent<Drivetrain>(); if (unityCarObj.GetComponent<AxisCarController>()==null) axisCarController=unityCarObj.AddComponent<AxisCarController>() as AxisCarController; else axisCarController=unityCarObj.GetComponent<AxisCarController>(); /* if (unityCarObj.GetComponent<SoundController>()==null) soundController=unityCarObj.AddComponent<SoundController>() as SoundController; else soundController=unityCarObj.GetComponent<SoundController>(); soundController.enabled=false; */ if (unityCarObj.GetComponent<Axles>()==null) axles =unityCarObj.AddComponent<Axles>() as Axles; else axles =unityCarObj.GetComponent<Axles>(); // to avoid car assigned to default layer unityCarObj.layer=1; if (unityCarObj.transform.Find("Body")==null){ bodyDown = GameObject.CreatePrimitive(PrimitiveType.Cube); bodyDown.name="Body"; Object.DestroyImmediate(bodyDown.collider); bodyDown.transform.parent=unityCarObj.transform; bodyDown.transform.localPosition=Vector3.zero; bodyDown.transform.localRotation=Quaternion.identity; bodyDown.transform.localScale=new Vector3(1.5f,0.5f,4); bodyUp = GameObject.CreatePrimitive(PrimitiveType.Cube); bodyUp.name="Body"; Object.DestroyImmediate(bodyUp.collider); bodyUp.transform.parent=unityCarObj.transform; bodyUp.transform.localRotation=Quaternion.identity; bodyUp.transform.localScale=new Vector3(bodyDown.transform.localScale.x,bodyDown.transform.localScale.y*0.666f,bodyDown.transform.localScale.z/2); bodyUp.transform.localPosition=new Vector3(0,bodyDown.transform.localScale.y - (bodyDown.transform.localScale.y-bodyUp.transform.localScale.y)/2,0); } else{ bodyDown=unityCarObj.transform.Find("Body").gameObject; } if (unityCarObj.transform.Find("Collider")==null){ mcollider= new GameObject("ColliderDown"); mcollider.transform.parent=unityCarObj.transform; mcollider.transform.localPosition=Vector3.zero; mcollider.transform.localRotation=Quaternion.identity; boxColliderDown = mcollider.gameObject.AddComponent<BoxCollider>() as BoxCollider; boxColliderDown.transform.localScale=new Vector3(1.5f,0.5f,4); mcollider= new GameObject("ColliderUp"); mcollider.transform.parent=unityCarObj.transform; mcollider.transform.localRotation=Quaternion.identity; boxColliderUp = mcollider.gameObject.AddComponent<BoxCollider>() as BoxCollider; boxColliderUp.transform.localScale=new Vector3(boxColliderDown.transform.localScale.x,boxColliderDown.transform.localScale.y*0.666f,boxColliderDown.transform.localScale.z/2); boxColliderUp.transform.localPosition=new Vector3(0,boxColliderDown.transform.localScale.y-(boxColliderDown.transform.localScale.y-boxColliderUp.transform.localScale.y)/2,0); } else{ mcollider=unityCarObj.transform.Find("Collider").gameObject; boxColliderDown = mcollider.gameObject.GetComponent<BoxCollider>(); } if (unityCarObj.transform.Find("wheelFL")==null){ wheelFL = new GameObject("wheelFL"); wheelFL.transform.parent=unityCarObj.transform; wheel = wheelFL.gameObject.AddComponent<Wheel>() as Wheel; wheelFL.transform.localPosition=new Vector3(-boxColliderDown.transform.localScale.x/2+wheel.width/2, -0.1f, boxColliderDown.transform.localScale.z/2 - boxColliderDown.transform.localScale.z/8); wheelFL.transform.localRotation=Quaternion.identity; wheel.showForces=false; wheel.wheelPos=WheelPos.FRONT_LEFT; axles.frontAxle.leftWheel=wheel; model = GameObject.CreatePrimitive(PrimitiveType.Sphere); model.name="modelFL"; Object.DestroyImmediate(model.collider); model.transform.parent=wheelFL.transform; model.transform.localPosition=Vector3.zero; model.transform.localRotation=Quaternion.identity; model.transform.localScale=new Vector3(wheel.width,wheel.radius*2,wheel.radius*2); wheel.model=model; } else{ wheelFL=unityCarObj.transform.Find("wheelFL").gameObject; } if (LayerMask.NameToLayer("Wheel")!=-1) wheelFL.gameObject.layer=LayerMask.NameToLayer("Wheel"); if (unityCarObj.transform.Find("wheelFR")==null){ wheelFR = new GameObject("wheelFR"); wheelFR.transform.parent=unityCarObj.transform; wheel = wheelFR.gameObject.AddComponent<Wheel>() as Wheel; wheelFR.transform.localPosition=new Vector3(boxColliderDown.transform.localScale.x/2-wheel.width/2, -0.1f, boxColliderDown.transform.localScale.z/2 - boxColliderDown.transform.localScale.z/8); wheelFR.transform.localRotation=Quaternion.identity; wheel.showForces=false; wheel.wheelPos=WheelPos.FRONT_RIGHT; axles.frontAxle.rightWheel=wheel; model = GameObject.CreatePrimitive(PrimitiveType.Sphere); model.name="modelFR"; Object.DestroyImmediate(model.collider); model.transform.parent=wheelFR.transform; model.transform.localPosition=Vector3.zero; model.transform.localRotation=Quaternion.identity; model.transform.localScale=new Vector3(wheel.width,wheel.radius*2,wheel.radius*2); wheel.model=model; } else{ wheelFR=unityCarObj.transform.Find("wheelFR").gameObject; } if (LayerMask.NameToLayer("Wheel")!=-1) wheelFR.gameObject.layer=LayerMask.NameToLayer("Wheel"); if (unityCarObj.transform.Find("wheelRL")==null){ wheelRL = new GameObject("wheelRL"); wheelRL.transform.parent=unityCarObj.transform; wheel = wheelRL.gameObject.AddComponent<Wheel>() as Wheel; wheelRL.transform.localPosition=new Vector3(-boxColliderDown.transform.localScale.x/2+wheel.width/2, -0.1f, -(boxColliderDown.transform.localScale.z/2 - boxColliderDown.transform.localScale.z/8)); wheelRL.transform.localRotation=Quaternion.identity; wheel.showForces=false; wheel.wheelPos=WheelPos.REAR_LEFT; axles.rearAxle.leftWheel=wheel; model = GameObject.CreatePrimitive(PrimitiveType.Sphere); model.name="modelRL"; Object.DestroyImmediate(model.collider); model.transform.parent=wheelRL.transform; model.transform.localPosition=Vector3.zero; model.transform.localRotation=Quaternion.identity; model.transform.localScale=new Vector3(wheel.width,wheel.radius*2,wheel.radius*2); wheel.model=model; } else{ wheelRL=unityCarObj.transform.Find("wheelRL").gameObject; } if (LayerMask.NameToLayer("Wheel")!=-1) wheelRL.gameObject.layer=LayerMask.NameToLayer("Wheel"); if (unityCarObj.transform.Find("wheelRR")==null){ wheelRR = new GameObject("wheelRR"); wheelRR.transform.parent=unityCarObj.transform; wheel = wheelRR.gameObject.AddComponent<Wheel>() as Wheel; wheelRR.transform.localPosition=new Vector3(boxColliderDown.transform.localScale.x/2-wheel.width/2, -0.1f, -(boxColliderDown.transform.localScale.z/2 - boxColliderDown.transform.localScale.z/8)); wheelRR.transform.localRotation=Quaternion.identity; wheel.showForces=false; wheel.wheelPos=WheelPos.REAR_RIGHT; axles.rearAxle.rightWheel=wheel; model = GameObject.CreatePrimitive(PrimitiveType.Sphere); model.name="modelRR"; Object.DestroyImmediate(model.collider); model.transform.parent=wheelRR.transform; model.transform.localPosition=Vector3.zero; model.transform.localRotation=Quaternion.identity; model.transform.localScale=new Vector3(wheel.width,wheel.radius*2,wheel.radius*2); wheel.model=model; } else{ wheelRR=unityCarObj.transform.Find("wheelRR").gameObject; } if (LayerMask.NameToLayer("Wheel")!=-1) wheelRR.gameObject.layer=LayerMask.NameToLayer("Wheel"); axles.frontAxle.maxSteeringAngle=33; axles.frontAxle.handbrakeFrictionTorque=0; axles.rearAxle.maxSteeringAngle=0; axles.rearAxle.handbrakeFrictionTorque=1000; axles.frontAxle.tires=CarDynamics.Tires.competition_front; axles.rearAxle.tires=CarDynamics.Tires.competition_rear; axles.SetWheels(); /* dashBoard = (GameObject)Instantiate(Resources.Load("Samples/Prefabs/Cars/DashBoard")); if (dashBoard ){ dashBoard.transform.parent=unityCarObj.transform; dashBoard.transform.localPosition=Vector3.zero; dashBoard.transform.localRotation=Quaternion.identity; } */ // These are to avoid warning about "assigned but never used" drivetrain.enabled=true; axisCarController.enabled=true; return unityCarObj; }
public static GameObject CreateNewCar() { GameObject unityCarObj = new GameObject("UnityCar"); if (unityCarObj.rigidbody == null) { mrigidbody = unityCarObj.AddComponent <Rigidbody>() as Rigidbody; mrigidbody.mass = 1000; mrigidbody.angularDrag = 0; mrigidbody.interpolation = RigidbodyInterpolation.Interpolate; } else { mrigidbody = unityCarObj.GetComponent <Rigidbody>(); } if (unityCarObj.GetComponent <CarDynamics>() == null) { carDynamics = unityCarObj.AddComponent <CarDynamics>() as CarDynamics; } else { carDynamics = unityCarObj.GetComponent <CarDynamics>(); } centerOfMassObject = new GameObject("COG"); centerOfMassObject.transform.parent = unityCarObj.transform; centerOfMassObject.transform.localPosition = Vector3.zero; centerOfMassObject.transform.localRotation = Quaternion.identity; carDynamics.centerOfMass = centerOfMassObject.transform; if (unityCarObj.GetComponent <Drivetrain>() == null) { drivetrain = unityCarObj.AddComponent <Drivetrain>() as Drivetrain; } else { drivetrain = unityCarObj.GetComponent <Drivetrain>(); } if (unityCarObj.GetComponent <AxisCarController>() == null) { axisCarController = unityCarObj.AddComponent <AxisCarController>() as AxisCarController; } else { axisCarController = unityCarObj.GetComponent <AxisCarController>(); } /* * if (unityCarObj.GetComponent<SoundController>()==null) * soundController=unityCarObj.AddComponent<SoundController>() as SoundController; * else * soundController=unityCarObj.GetComponent<SoundController>(); * * soundController.enabled=false; */ if (unityCarObj.GetComponent <Axles>() == null) { axles = unityCarObj.AddComponent <Axles>() as Axles; } else { axles = unityCarObj.GetComponent <Axles>(); } // to avoid car assigned to default layer unityCarObj.layer = 1; if (unityCarObj.transform.Find("Body") == null) { bodyDown = GameObject.CreatePrimitive(PrimitiveType.Cube); bodyDown.name = "Body"; Object.DestroyImmediate(bodyDown.collider); bodyDown.transform.parent = unityCarObj.transform; bodyDown.transform.localPosition = Vector3.zero; bodyDown.transform.localRotation = Quaternion.identity; bodyDown.transform.localScale = new Vector3(1.5f, 0.5f, 4); bodyUp = GameObject.CreatePrimitive(PrimitiveType.Cube); bodyUp.name = "Body"; Object.DestroyImmediate(bodyUp.collider); bodyUp.transform.parent = unityCarObj.transform; bodyUp.transform.localRotation = Quaternion.identity; bodyUp.transform.localScale = new Vector3(bodyDown.transform.localScale.x, bodyDown.transform.localScale.y * 0.666f, bodyDown.transform.localScale.z / 2); bodyUp.transform.localPosition = new Vector3(0, bodyDown.transform.localScale.y - (bodyDown.transform.localScale.y - bodyUp.transform.localScale.y) / 2, 0); } else { bodyDown = unityCarObj.transform.Find("Body").gameObject; } if (unityCarObj.transform.Find("Collider") == null) { mcollider = new GameObject("ColliderDown"); mcollider.transform.parent = unityCarObj.transform; mcollider.transform.localPosition = Vector3.zero; mcollider.transform.localRotation = Quaternion.identity; boxColliderDown = mcollider.gameObject.AddComponent <BoxCollider>() as BoxCollider; boxColliderDown.transform.localScale = new Vector3(1.5f, 0.5f, 4); mcollider = new GameObject("ColliderUp"); mcollider.transform.parent = unityCarObj.transform; mcollider.transform.localRotation = Quaternion.identity; boxColliderUp = mcollider.gameObject.AddComponent <BoxCollider>() as BoxCollider; boxColliderUp.transform.localScale = new Vector3(boxColliderDown.transform.localScale.x, boxColliderDown.transform.localScale.y * 0.666f, boxColliderDown.transform.localScale.z / 2); boxColliderUp.transform.localPosition = new Vector3(0, boxColliderDown.transform.localScale.y - (boxColliderDown.transform.localScale.y - boxColliderUp.transform.localScale.y) / 2, 0); } else { mcollider = unityCarObj.transform.Find("Collider").gameObject; boxColliderDown = mcollider.gameObject.GetComponent <BoxCollider>(); } if (unityCarObj.transform.Find("wheelFL") == null) { wheelFL = new GameObject("wheelFL"); wheelFL.transform.parent = unityCarObj.transform; wheel = wheelFL.gameObject.AddComponent <Wheel>() as Wheel; wheelFL.transform.localPosition = new Vector3(-boxColliderDown.transform.localScale.x / 2 + wheel.width / 2, -0.1f, boxColliderDown.transform.localScale.z / 2 - boxColliderDown.transform.localScale.z / 8); wheelFL.transform.localRotation = Quaternion.identity; wheel.showForces = false; wheel.wheelPos = WheelPos.FRONT_LEFT; axles.frontAxle.leftWheel = wheel; model = GameObject.CreatePrimitive(PrimitiveType.Sphere); model.name = "modelFL"; Object.DestroyImmediate(model.collider); model.transform.parent = wheelFL.transform; model.transform.localPosition = Vector3.zero; model.transform.localRotation = Quaternion.identity; model.transform.localScale = new Vector3(wheel.width, wheel.radius * 2, wheel.radius * 2); wheel.model = model; } else { wheelFL = unityCarObj.transform.Find("wheelFL").gameObject; } if (LayerMask.NameToLayer("Wheel") != -1) { wheelFL.gameObject.layer = LayerMask.NameToLayer("Wheel"); } if (unityCarObj.transform.Find("wheelFR") == null) { wheelFR = new GameObject("wheelFR"); wheelFR.transform.parent = unityCarObj.transform; wheel = wheelFR.gameObject.AddComponent <Wheel>() as Wheel; wheelFR.transform.localPosition = new Vector3(boxColliderDown.transform.localScale.x / 2 - wheel.width / 2, -0.1f, boxColliderDown.transform.localScale.z / 2 - boxColliderDown.transform.localScale.z / 8); wheelFR.transform.localRotation = Quaternion.identity; wheel.showForces = false; wheel.wheelPos = WheelPos.FRONT_RIGHT; axles.frontAxle.rightWheel = wheel; model = GameObject.CreatePrimitive(PrimitiveType.Sphere); model.name = "modelFR"; Object.DestroyImmediate(model.collider); model.transform.parent = wheelFR.transform; model.transform.localPosition = Vector3.zero; model.transform.localRotation = Quaternion.identity; model.transform.localScale = new Vector3(wheel.width, wheel.radius * 2, wheel.radius * 2); wheel.model = model; } else { wheelFR = unityCarObj.transform.Find("wheelFR").gameObject; } if (LayerMask.NameToLayer("Wheel") != -1) { wheelFR.gameObject.layer = LayerMask.NameToLayer("Wheel"); } if (unityCarObj.transform.Find("wheelRL") == null) { wheelRL = new GameObject("wheelRL"); wheelRL.transform.parent = unityCarObj.transform; wheel = wheelRL.gameObject.AddComponent <Wheel>() as Wheel; wheelRL.transform.localPosition = new Vector3(-boxColliderDown.transform.localScale.x / 2 + wheel.width / 2, -0.1f, -(boxColliderDown.transform.localScale.z / 2 - boxColliderDown.transform.localScale.z / 8)); wheelRL.transform.localRotation = Quaternion.identity; wheel.showForces = false; wheel.wheelPos = WheelPos.REAR_LEFT; axles.rearAxle.leftWheel = wheel; model = GameObject.CreatePrimitive(PrimitiveType.Sphere); model.name = "modelRL"; Object.DestroyImmediate(model.collider); model.transform.parent = wheelRL.transform; model.transform.localPosition = Vector3.zero; model.transform.localRotation = Quaternion.identity; model.transform.localScale = new Vector3(wheel.width, wheel.radius * 2, wheel.radius * 2); wheel.model = model; } else { wheelRL = unityCarObj.transform.Find("wheelRL").gameObject; } if (LayerMask.NameToLayer("Wheel") != -1) { wheelRL.gameObject.layer = LayerMask.NameToLayer("Wheel"); } if (unityCarObj.transform.Find("wheelRR") == null) { wheelRR = new GameObject("wheelRR"); wheelRR.transform.parent = unityCarObj.transform; wheel = wheelRR.gameObject.AddComponent <Wheel>() as Wheel; wheelRR.transform.localPosition = new Vector3(boxColliderDown.transform.localScale.x / 2 - wheel.width / 2, -0.1f, -(boxColliderDown.transform.localScale.z / 2 - boxColliderDown.transform.localScale.z / 8)); wheelRR.transform.localRotation = Quaternion.identity; wheel.showForces = false; wheel.wheelPos = WheelPos.REAR_RIGHT; axles.rearAxle.rightWheel = wheel; model = GameObject.CreatePrimitive(PrimitiveType.Sphere); model.name = "modelRR"; Object.DestroyImmediate(model.collider); model.transform.parent = wheelRR.transform; model.transform.localPosition = Vector3.zero; model.transform.localRotation = Quaternion.identity; model.transform.localScale = new Vector3(wheel.width, wheel.radius * 2, wheel.radius * 2); wheel.model = model; } else { wheelRR = unityCarObj.transform.Find("wheelRR").gameObject; } if (LayerMask.NameToLayer("Wheel") != -1) { wheelRR.gameObject.layer = LayerMask.NameToLayer("Wheel"); } axles.frontAxle.maxSteeringAngle = 33; axles.frontAxle.handbrakeFrictionTorque = 0; axles.rearAxle.maxSteeringAngle = 0; axles.rearAxle.handbrakeFrictionTorque = 1000; axles.frontAxle.tires = CarDynamics.Tires.competition_front; axles.rearAxle.tires = CarDynamics.Tires.competition_rear; axles.SetWheels(); /* dashBoard = (GameObject)Instantiate(Resources.Load("Samples/Prefabs/Cars/DashBoard")); * if (dashBoard ){ * dashBoard.transform.parent=unityCarObj.transform; * dashBoard.transform.localPosition=Vector3.zero; * dashBoard.transform.localRotation=Quaternion.identity; * } */ // These are to avoid warning about "assigned but never used" drivetrain.enabled = true; axisCarController.enabled = true; return(unityCarObj); }
void Start() { drivetrain = GetComponent <Drivetrain>(); axles = GetComponent <Axles>(); forceFeedback = GetComponent <ForceFeedback>(); }
void Awake(){ engineTorqueFromFile=false; torqueRPMValuesLen=0; body=rigidbody; myTransform=transform; clutch = new Clutch(); carController = GetComponent <CarController>(); setup= GetComponent <Setup>(); axles=GetComponent <Axles>(); fuelTanks=GetComponentsInChildren<FuelTank>(); poweredWheels=axles.rearAxle.wheels; // to avoid NullReferenceException }
void Start() { myTransform = transform; trs = myTransform.parent; //while (trs != null && trs.rigidbody == null) trs = trs.parent; //if (trs != null) body = trs.rigidbody; //Rigidbody rb = trs.GetComponent<Rigidbody>(); //while (trs != null && trs.gameObject.GetComponent<Rigidbody>() == null) trs = trs.parent; //if (trs != null) body = trs.gameObject.GetComponent<Rigidbody>(); if (body == null) { Rigidbody rb; do { rb = trs.GetComponent <Rigidbody>(); trs = trs.parent; }while (trs != null && rb == null); if (trs != null) { body = rb; } } //if (!trs.TryGetComponent<Rigidbody>(out body)) trs = trs.parent; trs = myTransform.parent; while (trs.GetComponent <PhysicMaterials>() == null) { if (trs.parent) { trs = trs.parent; } else { break; } } physicMaterials = trs.GetComponent <PhysicMaterials>(); trs = myTransform.parent; while (trs.GetComponent <CarDynamics>() == null) { trs = trs.parent; } cardynamics = trs.GetComponent <CarDynamics>(); drivetrain = trs.GetComponent <Drivetrain>(); axles = trs.GetComponent <Axles>(); localScale = 1 / (trs.localScale.y * myTransform.localScale.y); layerMask = 1 << trs.gameObject.layer | 1 << myTransform.gameObject.layer; //LayerMask.NameToLayer("Wheel"); layerMask = ~layerMask; radiusLoaded = radius; if (rimRadius == 0) { rimRadius = radius * 0.735f; } sidewallHeight = radius - rimRadius; if (mass < 50 * cardynamics.invFixedTimeStepScalar) { mass = 50 * cardynamics.invFixedTimeStepScalar; } if (rotationalInertia == 0 || rotationalInertia < (mass / 2) * radius * radius) { rotationalInertia = (mass / 2) * radius * radius; } originalMass = mass; if (model == null) { model = new GameObject("temp_model"); model.transform.parent = transform; model.transform.localPosition = new Vector3(0, 0, 0); model.transform.localRotation = Quaternion.identity; Debug.LogWarning("UnityCar: wheel model in " + wheelPos + " is missing. Using empty object" + " (" + trs.name + ")"); } modelTransform = model.transform; if (caliperModel != null) { caliperModelTransform = caliperModel.transform; } skidmarks = cardynamics.skidmarks; //if (skidmarks) skidSmoke = skidmarks.GetComponentInChildren(typeof(ParticleEmitter)) as ParticleEmitter; //suspensionLineRenderer=gameObject.GetComponent<LineRenderer>(); //if (suspensionLineRenderer==null) suspensionLineRenderer = gameObject.AddComponent<LineRenderer>(); //suspensionLineRenderer.material = new Material(Shader.Find("Diffuse")); //suspensionLineRenderer.material.color = Color.yellow; //suspensionLineRenderer.SetWidth(0.01f,0.1f); //suspensionLineRenderer.useWorldSpace = false; //suspensionLineRenderer.castShadows = false; camber *= 1; // to avoid never assigned warning if (camber == 0) { up = myTransform.up; } else { camberRotation = Quaternion.AngleAxis(-camber, forwardNormal); up = camberRotation * myTransform.up; } SetTireStiffness(); }
public override void OnLoad() { gameObjects = new List <Objects>(); //Player Vehicles // For each vehicle in the game, a new instance of Vehicle class is initialized. SATSUMA = new Vehicle("SATSUMA(557kg, 248)"); FLATBED = new Vehicle("FLATBED"); GIFU = new Gifu("GIFU(750/450psi)"); HAYOSIKO = new Vehicle("HAYOSIKO(1500kg, 250)"); JONNEZ = new Vehicle("JONNEZ ES(Clone)"); KEKMET = new Vehicle("KEKMET(350-400psi)"); RUSKO = new Vehicle("RCO_RUSCKO12(270)"); FERNDALE = new Vehicle("FERNDALE(1630kg)"); CABIN = GameObject.Find("CABIN"); AXLES = SATSUMA.Object.GetComponent <Axles>(); CAR_DYNAMICS = SATSUMA.Object.GetComponent <CarDynamics>(); ModConsole.Print("Cars Done"); //Locations and objects that can be enabled and disabled easily on proximity gameObjects.Add(new Objects(GameObject.Find("BOAT"))); //Boat is not a Car, oddly enough. gameObjects.Add(new Objects(GameObject.Find("COTTAGE"))); gameObjects.Add(new Objects(GameObject.Find("DANCEHALL"))); gameObjects.Add(new Objects(GameObject.Find("INSPECTION"))); gameObjects.Add(new Objects(GameObject.Find("LANDFILL"))); gameObjects.Add(new Objects(GameObject.Find("PERAJARVI"))); gameObjects.Add(new Objects(GameObject.Find("RYKIPOHJA"))); gameObjects.Add(new Objects(GameObject.Find("SOCCER"))); gameObjects.Add(new Objects(GameObject.Find("WATERFACILITY"))); gameObjects.Add(new Objects(GameObject.Find("TREES1_COLL"))); gameObjects.Add(new Objects(GameObject.Find("TREES2_COLL"))); gameObjects.Add(new Objects(GameObject.Find("TREES3_COLL"))); // Initialize Store class STORE = new Store(); REPAIRSHOP = new RepairShop(); gameObjects.Add(new Objects(GameObject.Find("DRAGRACE"), 1100)); Transform buildings = GameObject.Find("Buildings").transform; // Find house of Teimo and detach it from Perajarvi, so it can be loaded and unloaded separately // It shouldn't cause any issues, but that needs testing. GameObject perajarvi = GameObject.Find("PERAJARVI"); perajarvi.transform.Find("HouseRintama4").parent = buildings; // Same for chicken house perajarvi.transform.Find("ChickenHouse").parent = buildings; // Chicken house (barn) close to player's house Transform playerChickenHouse = GameObject.Find("Buildings").transform.Find("ChickenHouse"); playerChickenHouse.parent = null; // Fix for church wall. Changing it's parent ot NULL, so it will not be loaded or unloaded. // It used to be changed to CHURCH gameobject, // but the Amis cars (yellow and grey cars) used to end up in the graveyard area. GameObject.Find("CHURCHWALL").transform.parent = null; // Fix for old house on the way from Perajarvi to Ventti's house (HouseOld5) perajarvi.transform.Find("HouseOld5").parent = buildings; // Perajarvi fixes for multiple objects with the same name. // Instead of being the part of Perajarvi, we're changing it to be the part of Buildings. foreach (Transform trans in perajarvi.GetComponentsInChildren <Transform>()) { // Fix for disappearing grain processing plant // https://my-summer-car.fandom.com/wiki/Grain_processing_plant if (trans.gameObject.name.Contains("silo")) { trans.parent = buildings; continue; } // Fix for Ventti's and Teimo's mailboxes (and pretty much all mailboxes that are inside of Perajarvi) if (trans.gameObject.name == "MailBox") { trans.parent = buildings; continue; } // Fix for greenhouses on the road from Perajarvi to Ventti's house if (trans.name == "Greenhouse") { trans.parent = buildings; continue; } } // Possible fix for Jokke. // Needs testing foreach (Transform trans in GameObject.Find("KILJUGUY").transform.GetComponentsInChildren <Transform>()) { gameObjects.Add(new Objects(trans.gameObject)); } // Removes the mansion from the Buildings, so the tires will not land under the mansion. GameObject.Find("autiotalo").transform.parent = null; ModConsole.Print("GameObjects Done"); //Things that should be enabled when out of proximity of the house gameObjects.Add(new Objects(GameObject.Find("NPC_CARS"), awayFromHouse: true)); gameObjects.Add(new Objects(GameObject.Find("RALLY"), awayFromHouse: true)); gameObjects.Add(new Objects(GameObject.Find("TRAFFIC"), awayFromHouse: true)); gameObjects.Add(new Objects(GameObject.Find("TRAIN"), awayFromHouse: true)); gameObjects.Add(new Objects(GameObject.Find("Buildings"), awayFromHouse: true)); gameObjects.Add(new Objects(GameObject.Find("TrafficSigns"), awayFromHouse: true)); gameObjects.Add(new Objects(GameObject.Find("ELEC_POLES"), awayFromHouse: true)); gameObjects.Add(new Objects(GameObject.Find("StreetLights"), awayFromHouse: true)); //TODO: Solve Bugs from Unloading/Reloading Satsuma // Bugs: // Can't open doors // May randomly fall through floor //TODO: // (*2) Figure out how to make repairs works at Fleetari's without loading it // (*1) Figure out how to trigger a restock at Tiemos on Thursdays without loading it. //NOTES: // (*1) Partially addressed the Teimo's issue, by unloading part of the shop // (*2) Partially addressed the same way as for Teimo's shop //Camera.main.farClipPlane = (int)RenderDistance.Value; //Helps with lower end GPU's. This specific value. Any others are wrong. PLAYER = GameObject.Find("PLAYER"); YARD = GameObject.Find("YARD"); //Used to find out how far the player is from the Object KINEMATIC = SATSUMA.Object.GetComponent <Rigidbody>(); // Initialize MinorObjects new MinorObjects(); ModConsole.Print("[KruFPS] Found all objects"); DrawDistance = float.Parse(RenderDistance.GetValue().ToString()); //Update saved draw distance variable HookAllSavePoints(); //Hook all save points (it's before first pass of Update) //Camera.main.gameObject.AddComponent<CameraHook>(); }
public DirectInputAxle GetAxle(int id) { return(Axles.ElementAtOrDefault(id)); }
protected virtual void Start() { body=rigidbody; cardynamics = GetComponent<CarDynamics>(); drivetrain = GetComponent<Drivetrain>(); axles = GetComponent <Axles>(); allWheels=axles.allWheels; myTransform=transform; }
void Start(){ drivetrain=GetComponent<Drivetrain>(); axles=GetComponent <Axles>(); forceFeedback=GetComponent <ForceFeedback>(); }
void Start() { myTransform=transform; body=rigidbody; if(meshFilters.Length==0){ //meshFilters = GetComponentsInChildren<MeshFilter>(); m_meshFilters = GetComponentsInChildren<MeshFilter>(); int k=0; for (i = 0; i < m_meshFilters.Length; i++){ if (m_meshFilters[i].collider==null) k++; } meshFilters=new MeshFilter[k]; k=0; for (i = 0; i < m_meshFilters.Length; i++){ if (m_meshFilters[i].collider==null){ meshFilters[k]=m_meshFilters[i]; k++; } } } if (meshCollider!=null){ //meshFilterColl=meshCollider.gameObject.GetComponent<MeshFilter>(); colliderVerts = meshCollider.sharedMesh.vertices; } LoadoriginalMeshData(); foreach(Transform child in transform){ if (child.gameObject.tag=="Body" || child.gameObject.name=="Body" || child.gameObject.name=="body") GObody=child.gameObject; } if (GObody) { sign=Mathf.Cos(GObody.transform.localEulerAngles.y*Mathf.Deg2Rad); if (GObody.transform.localEulerAngles.x!=0) rot=Quaternion.AngleAxis(GObody.transform.localEulerAngles.x*3,Vector3.right); } carDynamics = GetComponent<CarDynamics>(); axles = GetComponent<Axles>(); wheelLayer=axles.allWheels[0].transform.gameObject.layer; carLayer=transform.gameObject.layer; }
public override void OnLoad() { gameObjects = new List <GameObject>(); //Player Vehicles // For each vehicle in the game, a new instance of Vehicle class is initialized. SATSUMA = new Vehicle("SATSUMA(557kg, 248)"); SATSUMA_2 = GameObject.Find("SATSUMA(557kg, 248)"); FLATBED = new Vehicle("FLATBED"); GIFU = new Gifu("GIFU(750/450psi)"); HAYOSIKO = new Vehicle("HAYOSIKO(1500kg, 250)"); JONNEZ = new Vehicle("JONNEZ ES(Clone)"); KEKMET = new Vehicle("KEKMET(350-400psi)"); RUSKO = new Vehicle("RCO_RUSCKO12(270)"); FERNDALE = new Vehicle("FERNDALE(1630kg)"); CABIN = GameObject.Find("CABIN"); AXLES = SATSUMA_2.GetComponent <Axles>(); CAR_DYNAMICS = SATSUMA_2.GetComponent <CarDynamics>(); ModConsole.Print("Cars Done"); //Locations and objects that can be enabled and disabled easily on proximity gameObjects.Add(GameObject.Find("BOAT")); //Boat is not a Car, oddly enough. //gameObjects.Add(GameObject.Find("CABIN")); gameObjects.Add(GameObject.Find("COTTAGE")); gameObjects.Add(GameObject.Find("DANCEHALL")); //gameObjects.Add(GameObject.Find("DRAGRACE")); //Is broken when disabled, so leave enabled gameObjects.Add(GameObject.Find("INSPECTION")); gameObjects.Add(GameObject.Find("LANDFILL")); gameObjects.Add(GameObject.Find("PERAJARVI")); //gameObjects.Add(GameObject.Find("REPAIRSHOP")); //Has to be loaded for repairs and such - Maybe fixable gameObjects.Add(GameObject.Find("RYKIPOHJA")); gameObjects.Add(GameObject.Find("SOCCER")); gameObjects.Add(GameObject.Find("WATERFACILITY")); gameObjects.Add(GameObject.Find("KILJUGUY")); gameObjects.Add(GameObject.Find("CHURCHWALL")); gameObjects.Add(GameObject.Find("TREES1_COLL")); gameObjects.Add(GameObject.Find("TREES2_COLL")); gameObjects.Add(GameObject.Find("TREES3_COLL")); // Initialize Store class STORE = new Store(); REPAIRSHOP = new RepairShop(); // Find house of Teimo and detach it from Perajarvi, so it can be loaded and unloaded separately // It shouldn't cause any issues, but that needs testing. GameObject perajarvi = GameObject.Find("PERAJARVI"); GameObject TEIMO_HOUSE = perajarvi.transform.Find("HouseRintama4").gameObject; TEIMO_HOUSE.transform.parent = null; // Same for chicken house GameObject CHICKEN_HOUSE = perajarvi.transform.Find("ChickenHouse").gameObject; CHICKEN_HOUSE.transform.parent = null; // Now that Teimo's house and chicken house is separated from Perajarvi, we can manage them separately. We're throwing them to gameObjects. // Fixes the bug with both dissapearing when leaving Perajarvi, even tho logically they should still load when approached. gameObjects.Add(TEIMO_HOUSE); gameObjects.Add(CHICKEN_HOUSE); // Fix for disappearing grain processing plant // https://my-summer-car.fandom.com/wiki/Grain_processing_plant // // It also puts them to farGameObjects - objects that are larger and need to be rendered from further distance foreach (Transform trans in perajarvi.GetComponentsInChildren <Transform>()) { if (trans.gameObject.name.Contains("silo")) { trans.parent = null; farGameObjects.Add(trans.gameObject); } } // Chicken house (barn) close to player's house Transform playerChickenHouse = GameObject.Find("Buildings").transform.Find("ChickenHouse"); playerChickenHouse.parent = null; gameObjects.Add(playerChickenHouse.gameObject); ModConsole.Print("GameObjects Done"); //Things that should be enabled when out of proximity of the house awayFromHouse = new List <GameObject>(); awayFromHouse.Add(GameObject.Find("NPC_CARS")); awayFromHouse.Add(GameObject.Find("RALLY")); awayFromHouse.Add(GameObject.Find("TRAFFIC")); awayFromHouse.Add(GameObject.Find("TRAIN")); awayFromHouse.Add(GameObject.Find("Buildings")); awayFromHouse.Add(GameObject.Find("TrafficSigns")); awayFromHouse.Add(GameObject.Find("ELEC_POLES")); //TODO: Solve Bugs from Unloading/Reloading Satsuma // Bugs: // Can't open doors // May randomly fall through floor //TODO: // Figure out how to make repairs works at Fleetari's without loading it // (*1) Figure out how to trigger a restock at Tiemos on Thursdays without loading it. //NOTES: // (*1) Partially addressed the Teimo's issue, by unloading part of the shop //Camera.main.farClipPlane = (int)RenderDistance.Value; //Helps with lower end GPU's. This specific value. Any others are wrong. PLAYER = GameObject.Find("PLAYER"); YARD = GameObject.Find("YARD"); //Used to find out how far the player is from the Object KINEMATIC = SATSUMA.Object.GetComponent <Rigidbody>(); // Get all minor objects from the game world (like beer cases, sausages) // Only items that are in the listOfMinorObjects list, and also contain "(itemx)" in their name will be loaded // UPDATED: added support for (Clone) items GameObject[] allObjects = Object.FindObjectsOfType <GameObject>(); foreach (GameObject gameObject in allObjects) { foreach (string itemName in listOfMinorObjects) { if (gameObject.name.Contains(itemName) && gameObject.name.ContainsAny("(itemx)", "(Clone)")) { minorObjects.Add(gameObject); } } } ModConsole.Print("[KruFPS] Found all objects"); DrawDistance = float.Parse(RenderDistance.GetValue().ToString()); //Update saved draw distance variable HookAllSavePoints(); //Hook all save points (it's before first pass of Update) }