Ejemplo n.º 1
0
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="go">Vehicle game object.</param>
        public GameVehicle(GameObject go)
        {
            gameObject = go;

            dynamics = gameObject.GetComponent <CarDynamics>();
            Client.Assert(dynamics != null, "Missing car dynamics!");

            driveTrain = gameObject.GetComponent <Drivetrain>();

            axisCarController = gameObject.GetComponent <AxisCarController>();
            mpCarController   = gameObject.AddComponent <MPCarController>();

            PlayMakerFSM[] fsms = gameObject.GetComponentsInChildren <PlayMakerFSM>();

            foreach (var fsm in fsms)
            {
                if (fsm.FsmName == "PlayerTrigger")
                {
                    SetupPlayerTriggerHooks(fsm);

                    // Temp - use player trigger..
                    seatGameObject = fsm.gameObject;
                }
            }
        }
Ejemplo n.º 2
0
        private void setValues()
        {
            // Written, 28.10.2020

            try
            {
                // GameObjects
                this.satuma     = GameObject.Find("SATSUMA(557kg, 248)");
                this.drivetrain = this.satuma.GetComponent <Drivetrain>();
                this.drivetrain.clutchTorqueMultiplier = 10f;
                this.carSimulation = this.satuma.transform.FindChild("CarSimulation").gameObject;
                this.engine        = this.carSimulation.transform.FindChild("Engine").gameObject;
                this.exhaust       = this.carSimulation.transform.FindChild("Exhaust").gameObject;
                PlayMakerFSM exhaustFSM = PlayMakerFSM.FindFsmOnGameObject(this.exhaust, "Logic");
                this.fromEngine            = exhaustFSM.FsmVariables.FindFsmGameObject("LocationEngine").Value;
                this.fromEngineOrginalPos  = this.fromEngine.transform.localPosition;
                this.fromEngineOrginalRot  = this.fromEngine.transform.localRotation;
                this.fromHeaders           = exhaustFSM.FsmVariables.FindFsmGameObject("LocationHeaders").Value;
                this.fromHeadersOrginalPos = this.fromHeaders.transform.localPosition;
                this.fromHeadersOrginalRot = this.fromHeaders.transform.localRotation;
                this.fromMuffler           = exhaustFSM.FsmVariables.FindFsmGameObject("LocationMuffler").Value;
                this.fromMufflerOrginalPos = this.fromMuffler.transform.localPosition;
                this.fromMufflerOrginalRot = this.fromMuffler.transform.localRotation;
                this.fromPipe           = exhaustFSM.FsmVariables.FindFsmGameObject("LocationPipe").Value;
                this.fromPipeOrginalPos = this.fromPipe.transform.localPosition;
                this.fromPipeOrginalRot = this.fromPipe.transform.localRotation;

                this.whistleSound              = this.gameObject.transform.FindChild("turbospool").gameObject.GetComponent <AudioSource>();
                this.whistleSound.minDistance  = 1;
                this.whistleSound.maxDistance  = 10;
                this.whistleSound.spatialBlend = 1;
                this.whistleSound.loop         = true;
                this.flutterSound              = this.gameObject.transform.FindChild("flutter").gameObject.GetComponent <AudioSource>();
                this.flutterSound.minDistance  = 1;
                this.flutterSound.maxDistance  = 10;
                this.flutterSound.spatialBlend = 1;
                this.flutterSound.loop         = false;
                this.flutterSound.mute         = false;
                // PlaymakerFSM
                this.carCoolingFSM            = this.carSimulation.transform.FindChild("Car/Cooling").gameObject.GetComponent <PlayMakerFSM>();
                this.backfireEvent            = this.engine.transform.FindChild("Symptoms").gameObject.GetComponent <PlayMakerFSM>();
                this.engineFuel               = this.engine.transform.FindChild("Fuel").gameObject;
                this.fuelFSM                  = this.engineFuel.gameObject.GetComponent <PlayMakerFSM>();
                this.fuelEventFSM             = this.engineFuel.gameObject.GetComponents <PlayMakerFSM>()[1];
                this.airFuelMixture           = this.fuelEventFSM.FsmVariables.FindFsmFloat("Mixture");
                this.airDensity               = this.fuelEventFSM.FsmVariables.FindFsmFloat("AirDensity");
                this.fuelPumpEfficiency       = this.fuelFSM.FsmVariables.GetFsmFloat("FuelPumpEfficiency");
                this.coolingAirRateMultiplier = this.carCoolingFSM.FsmVariables.FindFsmFloat("CoolingAirRateModifier");
                this.playerStressLevel        = PlayMakerGlobals.Instance.Variables.FindFsmFloat("PlayerStress");
                //this.engineOilFSM = this.oil
                this.engineTemp     = PlayMakerGlobals.Instance.Variables.FindFsmFloat("EngineTemp");
                this.fuel           = PlayMakerGlobals.Instance.Variables.FindFsmFloat("Fuel");
                this.currentVehicle = PlayMakerGlobals.Instance.Variables.FindFsmString("PlayerCurrentVehicle");
            }
            catch (Exception ex)
            {
                TurboMod.print("ERROR: {0}", ex.StackTrace);
                throw ex;
            }
        }
Ejemplo n.º 3
0
    void Start()
    {
        engineSource = CreateAudioSource(engine);
        skidSource = CreateAudioSource(skid);

        drivetrain = GetComponent (typeof (Drivetrain)) as Drivetrain;
    }
Ejemplo n.º 4
0
 // Use this for initialization
 void Start()
 {
     //重心初始化
     if (_centerOfMass != null)
     {
         rigidbody.centerOfMass = _centerOfMass.localPosition;
         rigidbody.inertiaTensor *= _inertiaFactor;
     }
     _drivetrain = GetComponent(typeof(Drivetrain)) as Drivetrain;
     LogitechGSDK.LogiSteeringInitialize(false);//初始化控制器窗口
     if (LogitechGSDK.LogiIsConnected(0))
     {
         _properties.wheelRange = 900;
         _properties.forceEnable = true;
         _properties.overallGain = 80;
         _properties.springGain = 80;
         _properties.damperGain = 80;
         _properties.allowGameSettings = false;
         _properties.combinePedals = false;
         _properties.defaultSpringEnabled = true;
         _properties.defaultSpringGain = 80;
         LogitechGSDK.LogiSetPreferredControllerProperties(_properties);
     }
     _init = false;
 }
    void Start()
    {
        if (centerOfMass != null)
        {
            this.GetComponent <Rigidbody>().centerOfMass = centerOfMass.localPosition;
        }
        this.GetComponent <Rigidbody>().inertiaTensor *= inertiaFactor;
        drivetrain = this.GetComponent <Drivetrain>();
        //driftController_ = GetComponent<DriftController>();

        switch (Application.platform)
        {
        case RuntimePlatform.Android:
            MoblieController.SetActive(true);

            // 設定手機可以用陀螺儀
            Input.gyro.enabled = true;
            break;
        }

        //For camera test scene
        //if(GetComponent<AutoCarController>() != null)
        //{
        //    bAutoControlled = true;
        //}
    }
Ejemplo n.º 6
0
	void Start ()
	{
	  drivetrain = transform.parent.GetComponent<Drivetrain>();
    axisCarController = transform.parent.GetComponent<AxisCarController>();
    if (smokes.Length > 0) 
      velocityZ = smokes[0].localVelocity.z;
	}
 void Start()
 {
     engineSource = CreateAudioSource(engine);
     skidSource = CreateAudioSource(skid);
     car = GetComponent (typeof (CarController)) as CarController;
     drivetrain = GetComponent (typeof (Drivetrain)) as Drivetrain;
 }
 void Start()
 {
     engineSource = GetComponents<AudioSource>()[0];
     skidSource = GetComponents<AudioSource>()[1];
     car = GetComponent (typeof (CarController)) as CarController;
     drivetrain = GetComponent (typeof (Drivetrain)) as Drivetrain;
 }
Ejemplo n.º 9
0
 void Start()
 {
     engineSource = CreateAudioSource(engine);
     skidSource   = CreateAudioSource(skid);
     car          = GetComponent(typeof(CarController)) as CarController;
     drivetrain   = GetComponent(typeof(Drivetrain)) as Drivetrain;
 }
Ejemplo n.º 10
0
        public override CarPart.CarPart Create()
        {
            var rearSuspension = new Suspension(
                type: GetRandomSuspensionType(),
                cost: randomGenerator.GetRandomValueInRange(40000, 100000),
                manufacturer: GetRandomManufacturer());
            var frontSuspension = new Suspension(
                type: GetRandomSuspensionType(),
                cost: randomGenerator.GetRandomValueInRange(40000, 100000),
                manufacturer: GetRandomManufacturer());

            var drivetrain = new Drivetrain(
                cost: randomGenerator.GetRandomValueInRange(30000, 100000),
                type: GetRandomDrivetrainType(),
                manufacturer: GetRandomManufacturer());

            var steeringPowerType = GetRandomSteeringPowerType();

            var brakeSystem = new BrakeSystem(
                type: GetRandomBrakesType(),
                cost: randomGenerator.GetRandomValueInRange(10000, 50000),
                manufacturer: GetRandomManufacturer());

            return(new Chassis(
                       manufacturer: GetRandomManufacturer(),
                       brakeSystem: brakeSystem,
                       drivetrain: drivetrain,
                       rearSuspension: rearSuspension,
                       frontSuspension: frontSuspension,
                       steeringPowerType: steeringPowerType,
                       wheels: new Wheel(
                           cost: randomGenerator.GetRandomValueInRange(10000, 30000),
                           manufacturer: GetRandomManufacturer())));
        }
Ejemplo n.º 11
0
 void Start()
 {
     drivetrain        = transform.parent.GetComponent <Drivetrain>();
     axisCarController = transform.parent.GetComponent <AxisCarController>();
     if (smokes.Length > 0)
     {
         velocityZ = smokes[0].localVelocity.z;
     }
 }
Ejemplo n.º 12
0
 private void switchCamera()
 {
     incrementIndex();
     carCamera.target = players[currentIndex].transform;
     string carId = players[currentIndex].GetComponent<CarController>().carId;
     playerIDText.text = carId;
     drivetrain = players[currentIndex].GetComponent<Drivetrain>();
     timer = players[currentIndex].GetComponent<Timer>();
 }
Ejemplo n.º 13
0
 void Start()
 {
     rb = GetComponent<Rigidbody>();
     if (centerOfMass != null)
         GetComponent<Rigidbody>().centerOfMass = centerOfMass.localPosition;
     GetComponent<Rigidbody>().inertiaTensor *= inertiaFactor;
     drivetrain = GetComponent (typeof (Drivetrain)) as Drivetrain;
     autoSteeringAngle = DataKeeper.dk.autoSteeringAngle;
 }
Ejemplo n.º 14
0
    private void OnTriggerEnter(Collider other)
    {
        Drivetrain drivetrain = other.gameObject.GetComponentInParent <Drivetrain>();

        if (drivetrain != null)
        {
            EnteredTrigger.Invoke(other);
        }
    }
 protected virtual void Start()
 {
     body        = rigidbody;
     cardynamics = GetComponent <CarDynamics>();
     drivetrain  = GetComponent <Drivetrain>();
     axles       = GetComponent <Axles>();
     allWheels   = axles.allWheels;
     myTransform = transform;
 }
Ejemplo n.º 16
0
 void Start()
 {
     body        = GetComponent <Rigidbody>();
     cardynamics = GetComponent <CarDynamics>();
     drivetrain  = GetComponent <Drivetrain>();
     axles       = GetComponent <Axles>();
     allWheels   = axles.allWheels;
     myTransform = transform;
 }
Ejemplo n.º 17
0
 // Initialize
 void Start()
 {
     if (centerOfMass != null)
     {
         GetComponent <Rigidbody>().centerOfMass = centerOfMass.localPosition;
     }
     GetComponent <Rigidbody>().inertiaTensor *= inertiaFactor;
     drivetrain = GetComponent(typeof(Drivetrain)) as Drivetrain;
 }
Ejemplo n.º 18
0
 public EnemyPlayer(GameObject car,Transform visualFoodTransofrm,Transform[] krillVis)
 {
     newTrace = new Dictionary<int, bool>();
     for(int i = 1; i <= 5; i++){
         newTrace[i] = false;
     }
     this.carTransform = car.transform;
     drivetrain = car.GetComponentInChildren<Drivetrain>();
     herd = new Herd(carTransform,krillVis,visualFoodTransofrm);
 }
Ejemplo n.º 19
0
    private void switchCamera()
    {
        incrementIndex();
        carCamera.target = players[currentIndex].transform;
        string carId = players[currentIndex].GetComponent <CarController>().carId;

        playerIDText.text = carId;
        drivetrain        = players[currentIndex].GetComponent <Drivetrain>();
        timer             = players[currentIndex].GetComponent <Timer>();
    }
Ejemplo n.º 20
0
 public EnemyPlayer(GameObject car, Transform visualFoodTransofrm, Transform[] krillVis)
 {
     newTrace = new Dictionary <int, bool>();
     for (int i = 1; i <= 5; i++)
     {
         newTrace[i] = false;
     }
     this.carTransform = car.transform;
     drivetrain        = car.GetComponentInChildren <Drivetrain>();
     herd = new Herd(carTransform, krillVis, visualFoodTransofrm);
 }
Ejemplo n.º 21
0
    // Initialize
    void Start()
    {
        if (centerOfMass != null)
        {
            rigidbody.centerOfMass = centerOfMass.localPosition;
        }
        rigidbody.inertiaTensor *= inertiaFactor;
        drivetrain = GetComponent(typeof(Drivetrain)) as Drivetrain;

        UIManager.GetInst().MainPlayerCarCtrl = this;
    }
Ejemplo n.º 22
0
 public void Assign(Drivetrain drivetrain)
 {
     if (Drivetrain == null)
     {
         Drivetrain = drivetrain;
     }
     else
     {
         throw new CarAlreadyHasDrivetrainException(this);
     }
 }
    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++;
            }
        }
    }
Ejemplo n.º 24
0
 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>();
     }
 }
Ejemplo n.º 25
0
	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>();
	}
Ejemplo n.º 26
0
        /// <summary>
        /// Sets all ffb to the current vehicle.
        /// </summary>
        private bool setFfbForVehicle()
        {
            // Written, 23.10.2020

            string _currentVehicleName = getCurrentVehicle;
            bool   isSet = (_currentVehicleName ?? "") == currentVehicleName;

            if (!isSet)
            {
                switch (_currentVehicleName)
                {
                case "Satsuma":
                    vehicle     = GameObject.Find("SATSUMA(557kg, 248)");
                    carDynamics = vehicle.GetComponent <CarDynamics>();
                    drivetrain  = vehicle.GetComponent <Drivetrain>();
                    break;

                case "Jonnez":
                    vehicle     = GameObject.Find("JONNEZ ES(Clone)");
                    carDynamics = vehicle.GetComponent <CarDynamics>();
                    drivetrain  = vehicle.GetComponent <Drivetrain>();
                    break;

                case "Kekmet":
                    vehicle     = GameObject.Find("KEKMET(350-400psi)");
                    carDynamics = vehicle.GetComponent <CarDynamics>();
                    drivetrain  = vehicle.GetComponent <Drivetrain>();
                    break;

                case "Hayosiko":
                    vehicle     = GameObject.Find("HAYOSIKO(1500kg, 250)");
                    carDynamics = vehicle.GetComponent <CarDynamics>();
                    drivetrain  = vehicle.GetComponent <Drivetrain>();
                    break;

                case "Gifu":
                    vehicle     = GameObject.Find("GIFU(750/450psi)");
                    carDynamics = vehicle.GetComponent <CarDynamics>();
                    drivetrain  = vehicle.GetComponent <Drivetrain>();
                    break;

                default:
                    vehicle = null;
                    break;
                }
                currentVehicleName = _currentVehicleName;
            }
            return(vehicle != null);
        }
Ejemplo n.º 27
0
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="go"></param>
        public PlayerVehicle(GameObject go, ObjectSyncComponent osc)
        {
            gameObject       = go;
            syncComponent    = osc;
            ParentGameObject = go.transform.parent.parent.gameObject;

            rigidbody  = ParentGameObject.GetComponent <Rigidbody>();
            dynamics   = ParentGameObject.GetComponent <CarDynamics>();
            driveTrain = ParentGameObject.GetComponent <Drivetrain>();

            axisCarController = ParentGameObject.GetComponent <AxisCarController>();
            mpCarController   = ParentGameObject.AddComponent <MPCarController>();

            FindFSMs();
        }
Ejemplo n.º 28
0
    void Start()
    {
        myTransform = transform;

        Transform trs = myTransform.parent;

        while (trs.GetComponent <Drivetrain>() == null)
        {
            trs = trs.parent;
        }
        drivetrain = trs.GetComponent <Drivetrain>();

        // Make sure the property getters methods are called
        tankCapacity = tankCapacity;
        currentFuel  = currentFuel;
        fuelDensity  = fuelDensity;

        myTransform.gameObject.layer = drivetrain.transform.gameObject.layer;

        fuelTank = myTransform.gameObject.GetComponent <Rigidbody>();
        if (fuelTank == null)
        {
            fuelTank = myTransform.gameObject.AddComponent <Rigidbody>();
        }

        boxCollider = myTransform.gameObject.GetComponent <BoxCollider>();
        if (boxCollider == null)
        {
            boxCollider      = myTransform.gameObject.AddComponent <BoxCollider>() as BoxCollider;
            boxCollider.size = new Vector3(0.7f, 0.25f, 0.6f);
        }

        // Set the fuel tank rigidbody parameters
        fuelTank.drag        = 0f;
        fuelTank.angularDrag = 0f;
        fuelTank.useGravity  = true;
        fuelTank.isKinematic = false;

        // Attach the fuel tank to the Car Chassis
        FixedJoint join = fuelTank.GetComponent <FixedJoint>();

        if (join == null)
        {
            join = fuelTank.gameObject.AddComponent <FixedJoint>();
        }
        join.connectedBody = drivetrain.transform.GetComponent <Rigidbody>();
    }
Ejemplo n.º 29
0
        private void LateUpdate()
        {
            // Written, 25.03.2019

            this.drivetrain = this.gameObject.GetComponent <Drivetrain>();

            if (this.drivetrain.rpm > this.initialRpm)
            {
                if (this.drivetrain.rpm > this.rpmAtMaxBoost)
                {
                    this.drivetrain.powerMultiplier = (this.rpmAtMaxBoost * this.boostMultiplier) + (this.boost * 0.1f);
                }
                else
                {
                    this.drivetrain.powerMultiplier = (this.drivetrain.rpm * this.boostMultiplier) + (this.boost * 0.1f);
                }
            }
        }
Ejemplo n.º 30
0
    // Initialize
    void Start()
    {
        if (isHuman)
        {
            player = new HumanPlayer();
        }
        else
        {
            player = new EnemyPlayer(gameObject, visualFoodTransform, krillVis);
        }

        if (centerOfMass != null)
        {
            rigidbody.centerOfMass = centerOfMass.localPosition;
        }
        rigidbody.inertiaTensor *= inertiaFactor;
        drivetrain = GetComponent <Drivetrain>();
    }
Ejemplo n.º 31
0
 public override void OnLoad()
 {
     {
         this.MOPED = GameObject.Find("JONNEZ ES(Clone)");
         Drivetrain[] component = this.MOPED.GetComponents <Drivetrain>();
         for (int i = 0; i < component.Length; i++)
         {
             Drivetrain playMakerFSM = component[i];
             {
                 playMakerFSM.revLimiter         = false;
                 playMakerFSM.maxPowerRPM        = (13000);
                 playMakerFSM.maxTorque          = (14);
                 playMakerFSM.powerMultiplier    = (1.3f);
                 playMakerFSM.externalMultiplier = (0.7f);
                 playMakerFSM.clutchMaxTorque    = (100);
             }
         }
     }
 }
Ejemplo n.º 32
0
        public override void OnLoad()
        {
            AssetBundle ab = AssetBundle.CreateFromMemoryImmediate(Properties.Resources.edm);

            edm = GameObject.Instantiate(ab.LoadAsset <GameObject>("EDM.prefab"));
            ab.Unload(false);

            saveManager = edm.GetComponent <SaveManager>();
            GameObject.DestroyImmediate(MenuColls);
            saveManager.Load();

            acc        = edm.GetComponent <AxisCarController>();
            drivetrain = edm.GetComponent <Drivetrain>();

            GameObject Shadow = GameObject.Instantiate(GameObject.Find("NPC_CARS").transform.Find("KUSKI/LOD/CarShadowProjector 3").gameObject);

            Shadow.transform.SetParent(edm.transform);
            Shadow.transform.localPosition    = new Vector3(0f, 0.54f, -0.2f);
            Shadow.transform.localEulerAngles = new Vector3(90f, 90f, 0f);
            Shadow.transform.localScale       = Vector3.one;
            Shadow.name = "CarShadowProjector";

            edm.AddComponent <CollisionSound>();

            //copy physics materials from hayosiko (can be any other car). (To know on what surface it will be driving)
            edm.GetComponent <CarDynamics>().physicMaterials = GameObject.Find("HAYOSIKO(1500kg, 250)").GetComponent <CarDynamics>().physicMaterials;

            //Add some skidmarks from hayosiko
            edm.GetComponent <CarDynamics>().skidmarks = GameObject.Find("HAYOSIKO(1500kg, 250)").GetComponent <CarDynamics>().skidmarks;

            #region Set up Lifts
            DrunkGuyLiftHandler liftHandler = edm.transform.Find("DrivingDoors").gameObject.AddComponent <DrunkGuyLiftHandler>();
            liftHandler.rightDoor    = edm.transform.Find("DrivingDoors/Doors/saloon_front_door_right").GetComponent <Door>();
            liftHandler.driveTrigger = edm.transform.Find("PlayerTrigger/DriveTrigger").GetComponent <PlayerDriveTrigger>();
            DrunkGuyMovingHandler movingHandler = edm.transform.Find("DrivingDoors").gameObject.AddComponent <DrunkGuyMovingHandler>();
            movingHandler.rightDoor    = edm.transform.Find("DrivingDoors/Doors/saloon_front_door_right").GetComponent <Door>();
            movingHandler.driveTrigger = edm.transform.Find("PlayerTrigger/DriveTrigger").GetComponent <PlayerDriveTrigger>();
            #endregion

            GameOptions();
            //edm.transform.Find("RainScript").gameObject.AddComponent<windshieldUVadjuster>();
        }
Ejemplo n.º 33
0
 void Start()
 {
     drivetrain = transform.parent.GetComponent <Drivetrain>();
     if (digitalSpeedoOnBoard != null)
     {
         textMeshSpeed = digitalSpeedoOnBoard.GetComponent <TextMesh>();
     }
     if (digitalGearOnBoard != null)
     {
         textMeshGear = digitalGearOnBoard.GetComponent <TextMesh>();
     }
     if (digitalSpeedoUnit == Unit.Kmh)
     {
         factor = 3.6f;
     }
     else
     {
         factor = 2.237f;
     }
 }
    /**********************************************************************************************************************************/



    // Use this for initialization
    void Start()
    {
        // Compute vehicle dimensions
        vehicleLength = bodyMesh.bounds.size.z;
        vehicleWidth  = bodyMesh.bounds.size.x;
        vehicleHeight = bodyMesh.bounds.size.y;

        // Compute wheel radius
        vehicleWheelRadius = wheelMeshLF.bounds.size.y / 2.0f;

        // Create drivetrain and resistance
        drivetrain = new Drivetrain(engineTorqueCurve, drivetrainGearRatios, drivetrainGearRatioFinalDrive, engineTuning, transmissionTuning, transmissionGearsTuning, differentialTuning, differentialGearsTuning);
        resistance = new Resistance(vehicleDragCoefficient, vehicleWidth, vehicleHeight, vehicleMass, bodyTuning, tiresTuning);

        // Create wheels
        wheelLF = new Wheel(wheelMeshLF);
        wheelLR = new Wheel(wheelMeshLR, tireParticleSystems[0]);
        wheelRF = new Wheel(wheelMeshRF);
        wheelRR = new Wheel(wheelMeshRR, tireParticleSystems[1]);
    }
Ejemplo n.º 35
0
    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");
    }
Ejemplo n.º 36
0
    void Start()
    {
        engineSource1 = CreateAudioSource(engine1, "Engine Audio 1");
        engineSource1.transform.localPosition = new Vector3(0f, 0.5f, 1.3f);
        //engineSource2 = CreateAudioSource(engine2 , "Engine Audio 2");

        skidSource = CreateAudioSource(skid, "Skidding Audio");
        car        = GetComponent(typeof(CarController)) as CarController;
        drivetrain = GetComponent(typeof(Drivetrain)) as Drivetrain;

        shiftUpSource          = CreateAudioSourceShift(shiftUp, "Shift Up Audio");
        shiftUpSource.volume   = 0.1f;
        shiftDownSource        = CreateAudioSourceShift(shiftDown, "Shift Down Audio");
        shiftDownSource.volume = 0.1f;

        blowOffValveSource = CreateAudioSourceShift(blowOffValve, "Blow Off Valve Audio");
        blowOffValveSource.transform.localPosition = new Vector3(-0.3f, 0.8f, 1.3f);

        transmissionOnSource  = CreateAudioSource(transmission[2], "Transmission On Audio");
        transmissionOffSource = CreateAudioSource(transmission[1], "Transmission Off Audio");
    }
Ejemplo n.º 37
0
	void Start(){
		myTransform=transform;
		
		Transform trs = myTransform.parent;		
		while (trs.GetComponent<Drivetrain>() == null)  trs = trs.parent;
		drivetrain = trs.GetComponent<Drivetrain>();	
		
		// Make sure the property getters methods are called
		tankCapacity = tankCapacity;
		currentFuel = currentFuel;
		fuelDensity = fuelDensity;
				
		myTransform.gameObject.layer=drivetrain.transform.gameObject.layer;
		
		fuelTank=myTransform.gameObject.GetComponent<Rigidbody>();
		if (fuelTank == null){
			fuelTank = myTransform.gameObject.AddComponent<Rigidbody>();
		}
		
		boxCollider=myTransform.gameObject.GetComponent<BoxCollider>();
		if (boxCollider==null){
			boxCollider = myTransform.gameObject.AddComponent<BoxCollider>() as BoxCollider;
			boxCollider.size=new Vector3(0.7f,0.25f,0.6f);
		}
		
		// Set the fuel tank rigidbody parameters
		fuelTank.drag = 0f;
		fuelTank.angularDrag = 0f;
		fuelTank.useGravity = true;
		fuelTank.isKinematic = false;
		
		// Attach the fuel tank to the Car Chassis
		FixedJoint join = fuelTank.GetComponent<FixedJoint>();
		if (join == null){
			join = fuelTank.gameObject.AddComponent<FixedJoint>();
		}
		join.connectedBody = drivetrain.transform.rigidbody;
		
	}
Ejemplo n.º 38
0
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="go"></param>
        public PlayerVehicle(GameObject go, ObjectSyncComponent osc)
        {
            gameObject       = go;
            syncComponent    = osc;
            ParentGameObject = go.transform.parent.parent.gameObject;

            if (ParentGameObject.name.StartsWith("JONNEZ"))
            {
                isBike        = true;
                steeringPivot = ParentGameObject.transform.FindChild("LOD/Suspension/Steering/SteeringPivot").gameObject;
            }

            rigidbody  = ParentGameObject.GetComponent <Rigidbody>();
            dynamics   = ParentGameObject.GetComponent <CarDynamics>();
            driveTrain = ParentGameObject.GetComponent <Drivetrain>();

            axisCarController = ParentGameObject.GetComponent <AxisCarController>();
            mpCarController   = ParentGameObject.AddComponent <MPCarController>();

            AddVehicleDoorSync();
            FindFSMs();
        }
Ejemplo n.º 39
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;
 }
Ejemplo n.º 40
0
    private void Start()
    {
        // 將輪胎裡面的 Curve 給進去
        curveM = this.GetComponent <CurveManager>();
        for (int i = 0; i < wheels.Length; i++)
        {
            wheels[i].CurveM = curveM;
        }

        Application.targetFrameRate = 30;
        QualitySettings.vSyncCount  = 0;

        // 拿東西
        if (centerOfMass != null)
        {
            this.GetComponent <Rigidbody>().centerOfMass = centerOfMass.localPosition;
        }
        this.GetComponent <Rigidbody>().inertiaTensor *= inertiaFactor;
        drivetrain = this.GetComponent <Drivetrain>();

        // 拿 NN Manager
        NNManger = this.GetComponent <NeuralNetworkManager>();
    }
Ejemplo n.º 41
0
 private void Start()
 {
   drivetrain = GetComponent<Drivetrain>();
   enabled = false;
 }
Ejemplo n.º 42
0
	//[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;
	}
Ejemplo n.º 43
0
    // Initialize
    void Start()
    {
        if(isHuman)
            player = new HumanPlayer();
        else{
            player = new EnemyPlayer(gameObject,visualFoodTransform,krillVis);
        }

        if (centerOfMass != null)
            rigidbody.centerOfMass = centerOfMass.localPosition;
        rigidbody.inertiaTensor *= inertiaFactor;
        drivetrain = GetComponent<Drivetrain>();
    }
Ejemplo n.º 44
0
	void Start(){
		drivetrain=transform.parent.GetComponent<Drivetrain>();
		if (digitalSpeedoOnBoard!=null) textMeshSpeed=digitalSpeedoOnBoard.GetComponent<TextMesh>();
		if (digitalGearOnBoard!=null) textMeshGear=digitalGearOnBoard.GetComponent<TextMesh>();
		if (digitalSpeedoUnit==Unit.Kmh) factor=3.6f;
		else factor=2.237f;
		
	}
Ejemplo n.º 45
0
 void Start()
 {
     engineSource = CreateAudioSource(engine, true,0,0.7f);
     startSource = CreateAudioSource(start, false,0.2f,0);
     drivetrain = GetComponent (typeof (Drivetrain)) as Drivetrain;
 }
	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++;
			}	
		}
	}
Ejemplo n.º 47
0
  protected virtual void Start()
  {
		body=rigidbody;
		cardynamics = GetComponent<CarDynamics>();
		drivetrain = GetComponent<Drivetrain>();
    axles = GetComponent <Axles>();
		allWheels=axles.allWheels;			
		myTransform=transform;
	}
Ejemplo n.º 48
0
	void Start(){
		drivetrain=GetComponent<Drivetrain>();
		axles=GetComponent <Axles>();
		forceFeedback=GetComponent <ForceFeedback>();
	}
Ejemplo n.º 49
0
	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;
				}
			}
		}
	}		
    // Initialize
    void Start()
    {
        //read in initial data
        string InitName = "initData.txt";
        StreamReader init_reader = null;
        try
        {
            init_reader = new StreamReader(InitName);
            for(string line = init_reader.ReadLine(); line != null; line = init_reader.ReadLine())
            {
                if(line != "" && line != "\n")
                {
                    string[]	a = line.Split(',');
                    checkPoint_L[0] = Convert.ToDouble(a[0]);
                    checkPoint_L[2] = Convert.ToDouble(a[1]);
                    checkPoint_L[4] = Convert.ToDouble(a[2]);
                }
                //Console.WriteLine(line);
            }
        }
        catch(IOException e)
        {
            Console.WriteLine(e.Message);
        }
        finally
        {
            if(init_reader!=null)
            init_reader.Close();
        }

        //read in recorded data
        string AmountName = "trackAmount.txt";
        if(record)
            File.Delete(AmountName);
        if(playback)
        {
            StreamReader reader = null;
            try
            {
                reader = new StreamReader(AmountName);
                for(string line = reader.ReadLine(); line != null; line = reader.ReadLine())
                {
                    if(line != "" && line != "\n")
                    {
                        record_amount = Convert.ToInt64(line);
                    }
                    //Console.WriteLine(line);
                }
            }
            catch(IOException e)
            {
                Console.WriteLine(e.Message);
            }
            finally
            {
                if(reader!=null)
                reader.Close();
            }
            //print(record_amount);
        }

        string FileName = "CarTrack.txt";
        if(record)
            File.Delete(FileName);
        if(playback)
        {
            StreamReader reader_data = null;
            trackRecords = new double[8, record_amount];
            try
            {
                reader_data = new StreamReader(FileName);
                for(string line = reader_data.ReadLine(); line != null; line = reader_data.ReadLine())
                {
                    if(line != "" && line != "\n")
                    {
                        string[]	a = line.Split(',');
                        for (int i = 0; i < 8; i++)
                        {
                            trackRecords[i, track_count] = Convert.ToDouble(a[i]);
                        }
                        //print(trackRecords[6, track_count]);
                        track_count++;

                    }
                    //Console.WriteLine(line);
                }
            }
            catch(IOException e)
            {
                Console.WriteLine(e.Message);
            }
            finally
            {
                if(reader_data!=null)
                reader_data.Close();
            }
        }

        if (centerOfMass != null)
        rigidbody.centerOfMass = centerOfMass.localPosition;
        rigidbody.inertiaTensor *= inertiaFactor;
        drivetrain = GetComponent (typeof (Drivetrain)) as Drivetrain;

        checkPoint_LHip[0] = checkPoint_RHip[0] = 1000;
        checkPoint_LHip[4] = checkPoint_RHip[4] = -1000;

        /*checkPoint_L[0] = -0.5550;
        checkPoint_L[2] = -0.2761;
        checkPoint_L[4] = 0.0028;*/
    }
Ejemplo n.º 51
0
	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;		
	}
Ejemplo n.º 52
0
 // Initialize
 void Start()
 {
     if (centerOfMass != null)
         rigidbody.centerOfMass = centerOfMass.localPosition;
     rigidbody.inertiaTensor *= inertiaFactor;
     drivetrain = GetComponent (typeof (Drivetrain)) as Drivetrain;
 }
Ejemplo n.º 53
0
	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();
	}