Inheritance: MonoBehaviour
Example #1
0
 // Start is called before the first frame update
 void Start()
 {
     controller    = GetComponent <CarControl>();
     rigidbody     = GetComponent <Rigidbody>();
     observation   = new List <float>();
     rotationEuler = gameObject.transform.rotation.eulerAngles;
 }
    public void OnCollision(ParticleSystem.CollisionEvent h, CarControl cc)
    {
        if (cc == pl.cc) return;
        Debug.DrawRay(h.intersection, h.normal, Color.red, 10);

        _Game.Hole(h.intersection, h.normal);

        if (_AutoQuality.particles || cc)
            _Game.Emit(h.intersection, h.normal, cc ? _Game.sparks : _Game.concrete);

        if (cc)
            cc.pl.PlayOneShot(res.damageSound.Random(), 1, true, Random.Range(.5f, 1));
        else if (Random.Range(1, 20) == 1)
            PlayClipAtPoint(res.ric.Random(), h.intersection);
        if (Time.time - lastTimeHit > .3f && cc)
        {
            lastTimeHit = Time.time;

            if (cc.pl.IsMine && cc.pl.IsEnemy(pl))
                cc.pl.AddLife(-(pl.pcVsAndroid ? 5 : 7), pl.viewId);

            if (_AutoQuality.destrQuality >= 2 || (pl.IsMine || cc.pl.IsMine) && _AutoQuality.destrQuality >= 1 && Random.Range(1, 3) == 1)
                cc.pl.OnCollision(h.intersection, 3, 10, true);
        }
    }
    // Use this for initialization
    void Start()
    {
        prefs      = PlayerPrefs.GetInt("qualityPrefs");
        carControl = GameObject.FindGameObjectWithTag("Player").GetComponent <CarControl>();
        gameOverCanvas.SetActive(false);
        prefs = 0;
        if (carControl.playerStates == CarControl.playerState.Idle)
        {
            StartCoroutine(flashText(spaceToStart));
        }

        if (prefs == 0)
        {
            PlayerPrefs.SetFloat("TotalScore", 0);
            PlayerPrefs.SetFloat("CogScore", 0);
            PlayerPrefs.SetFloat("DistanceTravelled", 0);
            PlayerPrefs.SetInt("qualityPrefs", 1);
        }
        else
        {
            tempTotalScore = PlayerPrefs.GetFloat("TotalScore");
            tempScore      = PlayerPrefs.GetFloat("CogScore");
            tempDistance   = PlayerPrefs.GetFloat("DistanceTravelled");
            PlayerPrefs.SetInt("qualityPrefs", 1);
        }
    }
Example #4
0
    public void PostProcess(Collision collision, bool enter)
    {
        Rigidbody otherRig = collision.rigidbody;

        if (enter && otherRig)
        {
            cc = otherRig.GetComponent <CarControl>();
        }

        if (otherRig && cc)
        {
            float f = Mathf.Clamp((otherRig.velocity.magnitude - rigidbody.velocity.magnitude) * Mathf.Max(1, otherRig.mass / rigidbody.mass), .5f, 2);
            m_sumImpactVelocity *= f;
            if (!android && room.collFix)
            {
                //ZeroY();
                rigidbody.angularVelocity = new Vector3(0, rigidbody.angularVelocity.y, 0);
            }
            colidesWith.value = cc.pl;
            if (enter && (colidesWith.value == _Player || m_Car.pl == _Player))
            {
                colidesWith.value.collisionTime = m_Car.pl.collisionTime = Time.time;
            }
        }
    }
 private void getVehicleComponents()
 {
     vehicleController = GetComponent <CarControl>();
     vehicleController.readUserInput = true;
     vehicleAudio    = GetComponent <CarSound>();
     vehicleSettings = GetComponent <CarSettings>();
 }
Example #6
0
    /// <summary>
    /// Тип AI - игрок. Есть возможность управления машиной CarControl, добавляет декали эфекты и звуки
    /// </summary>
    private void hlprScriptPlayer()
    {
        hlprScriptUndefined();

        CarControl carcontrol = null;

        //script (3)
        if (this.gameObject.GetComponent <CarControl>() == null)
        {
            carcontrol = this.gameObject.AddComponent <CarControl>();
        }
        if (this.gameObject.GetComponent <CarEffects>() == null)
        {
            this.gameObject.AddComponent <CarEffects>();
        }
        if (this.gameObject.GetComponent <CarSounds>() == null)
        {
            this.gameObject.AddComponent <CarSounds>();
        }

        //other (5)
        AddRigidBody(carcontrol.Drag);
        AddMeshCollider();
        AddFollowPos();
        AddEffectDust();
        AddBumper();
    }
Example #7
0
 void Start()
 {
     car     = transform.root.GetComponentInChildren <Car>().transform;
     oldZ    = car.rotation.eulerAngles.y;
     m_Car   = car.GetComponent <CarControl>();
     target  = car.FindChild("camToLookAt");
     _camera = GetComponent <Camera>();
 }
    public UserControl GetVehiculeControl()
    {
        if (m_control == null)
        {
            m_control = new CarControl();
        }

        return(m_control);
    }
Example #9
0
    void OnTriggerEnter(Collider collider)
    {
        CarControl m_car = collider.transform.root.GetComponentInChildren <CarControl>();

        if (m_car != null)
        {
            m_car.frontLightsOn();
        }
    }
Example #10
0
 void switchToNext()
 {
     if (next != null)
     {
         active = false;
         CarControl cc = (CarControl)next.GetComponent(typeof(CarControl));
         cc.Active();
     }
 }
Example #11
0
 public void OnEnabled()
 {
     car   = GetComponent <Car>();
     m_car = GetComponent <CarControl>();
     //  m_car.driftListner += driftHandler;
     //  tcs = car.accessories.tcsSystem;
     // if (tcs != null)
     //    tcsValue = tcs.m_TractionControl;
 }
    private void Awake()
    {
        carControl = GetComponent<CarControl>();
        flWheel = carControl.WheelFL;
        frWheel = carControl.WheelFR;
        rlWheel = carControl.WheelRL;
        rrWheel = carControl.WheelRR;

        JoinNodeNetwork();
    }
Example #13
0
 void OnEnable()
 {
     if (carControl == null)
     {
         carControl = GameObject.FindObjectOfType <CarControl>();
     }
     if (carControl == null)
     {
         gameObject.SetActive(false);
     }
 }
Example #14
0
 private void Start()
 {
     _carRigidBody  = this.gameObject.GetComponent <Rigidbody>();
     _carController = this.GetComponent <CarControl>();
     //_localTarget = path.GetPoint(0);
     //Debug.Log("target was at 0 " + _localTarget);
     _localTarget = GetClosestPoint(path);
     //Debug.Log("local target is "+ _localTarget);
     _targetAngle   = 0;
     manualOverride = false;
 }
Example #15
0
    public void onStart(CarControl m_Car)
    {
        this.m_Car = m_Car;
        //  if (wheelRadius == 0)

        m_Car.brakingListner  += neutralListner;
        m_Car.forwardListner  += setGearToFrist;
        m_Car.backwardListner += setGearToRevers;
        m_Car.neutralListner  += neutralListner;
        m_Car.stoppedListner  += setGearToN;
        wheelRadius            = m_Car.car.motorWheels[0].wheelCollider.radius;
    }
Example #16
0
        public static void Run()
        {
            Console.WriteLine("--- Start Question 3 ---");
            CarControl methods = new CarControl();

            Console.WriteLine(methods.Gas());
            Console.WriteLine(methods.Location());
            IProxyMethod proxy = new CarProxy();

            Console.WriteLine(proxy.Gas());
            Console.WriteLine(proxy.Location());
            Console.WriteLine("--- End Question 3 ---");
        }
    // Update is called once per frame
    void Update()
    {
        //FSM que maneja el flujo de la partida.
        switch (GameState)
        {
        //Si el estado es "Starting" comienza a correr la cuenta regresiva para iniciar la carrera. Se actualiza el texto correspondiente.
        case GameStates.Starting:
            if (startTimer <= 3 && startTimer > 0)
            {
                UIControl.SetStartText(Mathf.Ceil(startTimer).ToString());
            }
            else if (startTimer <= 0)
            {
                UIControl.SetStartText("GO!");
                GameState = GameStates.Playing; //Al completar la cuenta regresiva, se inicia la carrera.
                CarControl.StartCar();          //Se cambia el estado del auto de "Stopped" a "Accelerating".
            }
            startTimer -= Time.deltaTime;
            break;

        //Si el estado es "Playing", se actualiza el cronómetro del tiempo de la carrera.
        case GameStates.Playing:

            if (GameTimer <= 0 || CarControl.CarState == CarController.CarStates.Destroyed)
            {
                GameState = GameStates.Ending;     //Si el cronómetro llega a 0, se termina la carrera, pero no todavía la partida.
            }
            GameTimer -= Time.deltaTime;
            break;

        //Si el estado es "Ending", se comienza a frenar el auto
        case GameStates.Ending:
            if (CarControl.CarState != CarController.CarStates.Stopping && CarControl.CarState != CarController.CarStates.Stopped)
            {
                CarControl.StopCar();     //Si el auto se está moviendo, se aplica la fuerza de freno.
            }
            else if (CarControl.CarState == CarController.CarStates.Stopped)
            {
                EndGame();     //Si la velocidad del auto ya llegó a 0, se termina la partida.
                GameState = GameStates.Ended;
            }

            break;

        case GameStates.Ended:

            break;
        }
    }
Example #18
0
 void switchToPrev()
 {
     if (prev != null)
     {
         active = false;
         control.setVisible(false);
         CarControl cc = (CarControl)prev.GetComponent(typeof(CarControl));
         cc.Active();
     }
     else
     {
         Chooser.DestroyMaps();
         SceneManager.LoadScene(0);
     }
 }
    // Update is called once per frame
    void Update()
    {
        healthBar.fillAmount = carControl.health;
        if (carControl == null)
        {
            carControl = GameObject.FindGameObjectWithTag("Player").GetComponent <CarControl>();
        }
        if (carControl.playerStates == CarControl.playerState.Idle && carControl.inputDevice.Action3.WasPressed || Input.GetKeyDown(KeyCode.Space))
        {
            StopAllCoroutines();
            spaceToStart.gameObject.SetActive(false);
            carControl.playerStates = CarControl.playerState.Driving;
        }


        gameOverMenu();
    }
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            SetContentView(Resource.Layout.activity_race);

            sbrDirection  = FindViewById <SeekBar>(Resource.Id.sbrDirection);
            sbrSpeed      = FindViewById <SeekBar>(Resource.Id.sbrSpeed);
            chkAccellero  = FindViewById <CheckBox>(Resource.Id.chkAccellero);
            lblSpeed      = FindViewById <TextView>(Resource.Id.lblSpeed);
            lblDirection  = FindViewById <TextView>(Resource.Id.lblDirection);
            sensorManager = (SensorManager)GetSystemService(SensorService);
            carControl    = new CarControl();

            sbrDirection.ProgressChanged += SbrDirection_ProgressChanged;
            sbrSpeed.ProgressChanged     += SbrSpeed_ProgressChanged;
            chkAccellero.CheckedChange   += ChkAccellero_CheckedChange;
        }
Example #21
0
    public void LoadNeuralNetwork(float[,] nnSave)
    {
        sensors = GetComponent <Sensors>();
        carctrl = GetComponent <CarControl>();

        MakeBasic();

        for (int x = 0; x < 200; x++)
        {
            for (int y = 0; y < 200; y++)
            {
                if (nnSave[x, y] > 0)
                {
                    Connection c = new Connection();
                    allconnections.Add(c);
                    c.Weight = nnSave[x, y];

                    if (EveryNeuron[x] == null)
                    {
                        Neuron n = new Neuron();
                        EveryNeuron[x] = n;
                        HiddenNeurons.Add(n);
                        n.NeuronNumber = x;
                    }
                    if (EveryNeuron[y] == null)
                    {
                        Neuron n = new Neuron();
                        EveryNeuron[y] = n;
                        HiddenNeurons.Add(n);

                        n.NeuronNumber = y;
                    }
                    EveryNeuron[x].Links.Add(c);
                    c.In       = x;
                    c.neuronIn = EveryNeuron[x];

                    c.neuronOut = EveryNeuron[y];
                    c.Out       = y;
                    EveryNeuron[y].BackLinks.Add(c);
                }
            }
        }
        StartCoroutine("FeedForward");
    }
Example #22
0
    void LoadCar()
    {
        if (m_Car)
        {
            _Pool.Save(m_Car.gameObject);
        }
        string path     = cop ? "police" : owner.carSet.carName;
        Spawn  spawnPos = GetSpawnStartPos();

        m_Car = _Pool.Load2(Resources.Load(path), spawnPos.pos, spawnPos.rot).GetComponent <CarControl>();
        if (m_Car.m_CarDamage.meshTest)
        {
            m_Car.m_CarDamage.meshTest.Reset(this == _Player);
            m_Car.rigidbody.velocity = m_Car.rigidbody.angularVelocity = Vector3.zero;
        }

        //m_Car = ((GameObject)Instantiate(Resources.Load(path), spawnPos.pos, spawnPos.rot)).GetComponent<CarControl>();
        m_Car.name   = "Player Car " + pv.playerName;
        transformCar = m_Car.tr;
        rigidbody    = m_Car.rigidbody;
        rigidbody.solverIterationCount = 6;
        m_CarSettings           = m_Car.GetComponent <CarSettings>() as CarSettings;
        m_CarSound              = m_Car.GetComponent <CarSound>() as CarSound;
        m_CarSettings.bypassABS = false;
        m_Car.pl = this;
        OnQualityChanged();
        var priority = this == _Player ? 100 : 130;

        foreach (var a in GetComponents <AudioSource>())
        {
            a.priority = priority;
        }
        foreach (var a in m_Car.audioSources)
        {
            a.priority = priority;
        }

        if (IsMine && !bot2)
        {
            _Game.MainCamera.Target = m_Car.tr;
        }
        AmplifyMotionEffect.RegisterRecursivelyS(m_Car.gameObject);
    }
Example #23
0
    void setupPlayer()
    {
        CarControl carControl = car.GetComponent <CarControl>();

        // car.GetComponent<CarAudio>().enabled = true;
        //car.GetComponent<CarEffects>().enabled = true;
        car.GetComponent <TCSSystem>().enabled = true;

        car.gameObject.AddComponent <UserInput>();

        carControl.enabled = true;

        SpeedoMeter speedoMeter = GameObject.FindObjectOfType <SpeedoMeter>();

        if (speedoMeter != null)
        {
            speedoMeter.m_Car   = carControl;
            speedoMeter.enabled = true;
        }
    }
Example #24
0
 void Start()
 {
     powerupCooldownTime = DataManager.PowerupCooldownTime;
     car        = GameObject.FindGameObjectWithTag("Player");
     carControl = car.GetComponent <CarControl>();
     pSwitch    = gameObject.GetComponent <PlayerSwitching>();
     hud        = pSwitch.hudManager;
     foreach (PlayerData player in DataManager.PlayerList)
     {
         player.Lives = DataManager.LivesCount;
         if (StartingPowerUp != PowerUpType.None && pSwitch.DEBUG_MODE)
         {
             player.CurrentPowerUp = StartingPowerUp;
         }
         else
         {
             StartCoroutine(Cooldown(player));
             // RandomPowerup(player);
         }
     }
 }
    public void PostProcess(Collision collision, bool enter)
    {
        Rigidbody otherRig = collision.rigidbody;
        if (enter && otherRig)
            cc = otherRig.GetComponent<CarControl>();

        if (otherRig && cc)
        {
            float f = Mathf.Clamp((otherRig.velocity.magnitude - rigidbody.velocity.magnitude) * Mathf.Max(1, otherRig.mass / rigidbody.mass), .5f, 2);
            m_sumImpactVelocity *= f;
            if (!android && room.collFix)
            {
                //ZeroY();
                rigidbody.angularVelocity = new Vector3(0, rigidbody.angularVelocity.y, 0);
            }
            colidesWith.value = cc.pl;
            if (enter && (colidesWith.value == _Player || m_Car.pl == _Player))
                colidesWith.value.collisionTime = m_Car.pl.collisionTime = Time.time;

        }
    }
Example #26
0
    // Use this for initialization
    void Start()
    {
        carControl = GetComponent <CarControl>();
        Transform canvas = GameObject.Find("Canvas").transform;

        hudGO = GameObject.Find("HUD");
        Transform hud = hudGO.transform;

        position    = hud.Find("PositionLabel").GetComponent <Text>();
        pickup      = hud.Find("PickupLabel").GetComponent <Text>();
        timer       = canvas.Find("countDownTimer").GetComponent <Text>();
        fuelMeter   = hud.Find("FuelMeter").GetComponent <Slider>();
        damageMeter = hud.Find("DamageMeter").GetComponent <Slider>();
        hudEnabled  = false;
        countDown   = 5f;

        Transform respawn = hud.Find("Respawns").transform;

        respawnText  = respawn.Find("RespawnText").GetComponent <Text>();
        respawnTimer = respawn.Find("RespawnSlider").GetComponent <Slider>();
    }
Example #27
0
        public CarPage()
        {
            InitializeComponent();

            int     _columnIndex             = 0;
            int     _rowIndex                = 0;
            int     _countItemsDataTableCars = 0;
            Boolean _rotateButtonCarControl  = false;

            DataTable _dataTableCars = new DataTable();

            _dataTableCars = DB.RunSelectCommand("select * from Cars join CarTypes on Cars.Type=CarTypes.Id join" +
                                                 " FuelTypes on Cars.FuelType=FuelTypes.Id");

            foreach (DataRow _row in _dataTableCars.Rows)
            {
                Car car = new Car(
                    Convert.ToInt32(_row[0]),
                    _row[1].ToString(),
                    Convert.ToInt32(_row[3]),
                    _row[7].ToString(),
                    _row[12].ToString(),
                    _row[9].ToString(),
                    _row[6].ToString(),
                    _row[2].ToString());
                CarControl carButtonControll = new CarControl(car, _rotateButtonCarControl);

                Grid.SetRow(carButtonControll, _rowIndex);
                Grid.SetColumn(carButtonControll, _columnIndex);
                CarGrid.Children.Add(carButtonControll);
                _columnIndex             += 2;
                _countItemsDataTableCars += 1;
                if (_countItemsDataTableCars % 5 == 0)
                {
                    _rowIndex              += 4;
                    _columnIndex            = 0;
                    _rotateButtonCarControl = !_rotateButtonCarControl;
                }
            }
        }
Example #28
0
    public void OnCollision(ParticleSystem.CollisionEvent h, CarControl cc)
    {
        if (cc == pl.cc)
        {
            return;
        }
        Debug.DrawRay(h.intersection, h.normal, Color.red, 10);

        _Game.Hole(h.intersection, h.normal);

        if (_AutoQuality.particles || cc)
        {
            _Game.Emit(h.intersection, h.normal, cc ? _Game.sparks : _Game.concrete);
        }

        if (cc)
        {
            cc.pl.PlayOneShot(res.damageSound.Random(), 1, true, Random.Range(.5f, 1));
        }
        else if (Random.Range(1, 20) == 1)
        {
            PlayClipAtPoint(res.ric.Random(), h.intersection);
        }
        if (Time.time - lastTimeHit > .3f && cc)
        {
            lastTimeHit = Time.time;

            if (cc.pl.IsMine && cc.pl.IsEnemy(pl))
            {
                cc.pl.AddLife(-(pl.pcVsAndroid ? 5 : 7), pl.viewId);
            }

            if (_AutoQuality.destrQuality >= 2 || (pl.IsMine || cc.pl.IsMine) && _AutoQuality.destrQuality >= 1 && Random.Range(1, 3) == 1)
            {
                cc.pl.OnCollision(h.intersection, 3, 10, true);
            }
        }
    }
Example #29
0
    public void MakeRandomAndStart()
    {
        sensors = GetComponent <Sensors>();
        carctrl = GetComponent <CarControl>();
        for (int i = 0; i < 5; i++)
        {
            Neuron n = new Neuron();
            InputNeurons[i] = n;
            n.NeuronNumber  = i;
        }

        for (int i = 0; i < 2; i++)
        {
            Neuron n = new Neuron();
            //n.RandomizeNeuron();
            n.Threshhold     = Threshhold;
            OutputNeurons[i] = n;
            n.NeuronNumber   = i + 5;
        }
        MakeRandomHiddenNeurons();
        SetRandomConnections();

        StartCoroutine("FeedForward");
    }
    private void Awake()
    {
        carControl = GetComponent<CarControl>();

        headLights = new GameObject[2];
        headLights[0] = transform.FindChild("Light_Head_L").gameObject;
        headLights[1] = transform.FindChild("Light_Head_R").gameObject;

        tailLights = new GameObject[2];
        tailLights[0] = transform.FindChild("Light_Tail_L").gameObject;
        tailLights[1] = transform.FindChild("Light_Tail_R").gameObject;

        indicators = new GameObject[2];
        indicators[0] = transform.FindChild("Light_Indicator_L").gameObject;
        indicators[1] = transform.FindChild("Light_Indicator_R").gameObject;

        brakeLights = new GameObject[2];
        brakeLights[0] = transform.FindChild("Light_Brake_L").gameObject;
        brakeLights[1] = transform.FindChild("Light_Brake_R").gameObject;

        reverseLights = new GameObject[2];
        reverseLights[0] = transform.FindChild("Light_Reverse_L").gameObject;
        reverseLights[1] = transform.FindChild("Light_Reverse_R").gameObject;
    }
Example #31
0
 void Start()
 {
     car = GetComponent<Car>();
     machineGunControl = car.MachineGunControl;
     control = car.Control;
 }
 void Awake()
 {
     carControl = GetComponent<CarControl>();
 }
    //public new void print(object s)
    //{
    //    _Loader.sb.AppendLine(s + "");
    //}
    public bool UpdateInput(CarControl Car, bool reverseRequiresStop, bool brakeRelease)
    {
        if (!bot && IsMine && nitro <= 0)
            unpressKey.Add(KeyCode.LeftShift);

        if (Input2.GetKey(KeyCode.LeftShift))
            pressedKey.Add(KeyCode.W);
        nitroDown = InputGetKey(KeyCode.LeftShift);
        var factor = Time.deltaTime;
        bool left = InputGetKey(KeyCode.A);
        bool right = InputGetKey(KeyCode.D);
        var brake = InputGetKey(KeyCode.Space);
        var forward = InputGetKey(KeyCode.W) || nitroDown;
        var back = InputGetKey(KeyCode.S);

        steerValue = Lerp(steerValue, left ? -1 : right ? 1 : 0, factor);
        forwardValue = Lerp(forwardValue, forward ? 1 : 0, factor * 3);
        reverseValue = Lerp(reverseValue, back ? 1 : 0, factor * 3);
        if (forward)
            reverseValue = 0;
        if (back)
            forwardValue = 0;
        handbrakeValue = brake ? 1 : 0;

        float speedForward = Vector3.Dot(Car.rigidbody.velocity, Car.tr.forward);
        float speedSideways = Vector3.Dot(Car.rigidbody.velocity, Car.tr.right);
        float speedRotation = Car.rigidbody.angularVelocity.magnitude;
        float speedAbs = speedForward * speedForward;
        speedSideways *= speedSideways;
        float motorInput = 0;
        float brakeInput = 0;
        if (reverseRequiresStop)
        {
            if (speedAbs < GEARSPEEDMIN && forwardValue == 0 && reverseValue == 0)
            {
                brakeRelease = true;
                Car.gearInput = 0;
            }
            if (brakeRelease)
                if (speedAbs < GEARSPEEDMIN)
                {
                    if (reverseValue > 0)
                    {
                        Car.gearInput = -1;
                    }
                    if (forwardValue > 0)
                    {
                        Car.gearInput = 1;
                    }
                }
                else if (speedSideways < GEARSPEEDMIN && speedRotation < GEARSPEEDMIN)
                {
                    if (speedForward > 0 && Car.gearInput <= 0 && (forwardValue > 0 || reverseValue > 0))
                        Car.gearInput = 1;
                    if (speedForward < 0 && Car.gearInput >= 0 && (forwardValue > 0 || reverseValue > 0))
                        Car.gearInput = -1;
                }
            if (Car.gearInput < 0)
            {
                motorInput = reverseValue;
                brakeInput = forwardValue;
            }
            else
            {
                motorInput = forwardValue;
                brakeInput = reverseValue;
            }
            if (brakeInput > 0)
                brakeRelease = false;
        }
        else
        {
            if (speedForward > GEARSPEEDMIN)
            {
                Car.gearInput = 1;
                motorInput = forwardValue;
                brakeInput = reverseValue;
            }
            else if (speedForward <= GEARSPEEDMIN && reverseValue > GEARSPEEDMIN)
            {
                Car.gearInput = -1;
                motorInput = reverseValue;
                brakeInput = 0;
            }
            else if (forwardValue > GEARSPEEDMIN && reverseValue <= 0)
            {
                Car.gearInput = 1;
                motorInput = forwardValue;
                brakeInput = 0;
            }
            else if (forwardValue > GEARSPEEDMIN)
                Car.gearInput = 1;
            else if (reverseValue > GEARSPEEDMIN)
                Car.gearInput = -1;
            else
                Car.gearInput = 0;
            brakeRelease = false;
        }
        Car.steerInput = steerValue;
        Car.motorInput = motorInput;
        Car.brakeInput = brakeInput;
        Car.handbrakeInput = handbrakeValue;
        return brakeRelease;
    }
Example #34
0
    // ================================================================ //
    // 继承于MonoBehaviour

    void    Awake()
    {
        this.car_control = this.gameObject.GetComponent <CarControl>();
    }
Example #35
0
 // Start is called before the first frame update
 void Start()
 {
     m_Game = new CarControl();
     m_Game.SetGame();
 }
 private void getVehicleComponents()
 {
     vehicleController = GetComponent<CarControl>();
     vehicleController.readUserInput = true;
     vehicleAudio = GetComponent<CarSound>();
     vehicleSettings = GetComponent<CarSettings>();
 }
Example #37
0
    public void Update()
    {
        var time = Mathf.Min(extraTime, Time.deltaTime * 3);

        extraTime -= time;
        var deltaTime = Time.deltaTime + time;

        if (deltaTime == 0)
        {
            return;
        }

        var targetPl = _Game.players.TryGet(targetPlayer);

        if (targetPl)
        {
            rot = Quaternion.RotateTowards(rot, Quaternion.LookRotation(targetPl.pos - pos), Time.deltaTime * 20);
        }

        vel = tr.forward * bulletSpeed2 * deltaTime;
        if (dist > 1000 && !exploded)
        {
            Destroy2(gameObject);
        }
        dist += vel.magnitude;
        if (speedUp != 0)
        {
            bulletSpeed2 += speedUp * deltaTime;
            bulletSpeed2  = Mathf.Min(bulletSpeed2, maxSpeed2);
        }
        if (!exploded)
        {
            foreach (RaycastHit h in Physics.RaycastAll(tr.position, tr.forward, vel.magnitude + 3, Layer.allmask).OrderBy(a => a.distance))
            {
                MonoBehaviour bs     = h.transform.root.GetComponent <MonoBehaviour>();
                CarControl    cc     = bs as CarControl;
                Player        hitPl  = cc != null ? cc.pl : null;
                var           IsMine = wep.pl == _Player;

                //if (hitPl != null && !explosion)
                //{
                //    var b = remote2 ? !IsMine && hitPl.IsMine : IsMine;
                //    if (b && hitPl != wep.pl && !hitPl.dead)
                //    {
                //        if (wep.pl != null && wep.pl.IsEnemy(hitPl))
                //            hitPl.CallRPC(hitPl.SetLife, hitPl.life - wep.damage, wep.pl.viewId);
                //    }
                //    if (hitPl.IsEnemy(wep.pl) && checkVisible(h.point))
                //    {
                //        hitPl.OnCollision(h.point, 20);
                //        _Game.Emit(h.point, h.normal, _Game.sparks);
                //    }
                //}
                if ((hitPl != wep.pl || hitPl == null))
                {
                    if (explosion != null && IsMine)
                    {
                        pl.CallRPC(pl.Explode, h.point);
                    }

                    if (wep.bulletHitSound.Length > 0 && checkVisible(pos) && Vector3.Distance(_Player.pos, pos) < 100)
                    {
                        var audioClip = wep.bulletHitSound[Random.Range(0, wep.bulletHitSound.Length)];
                        PlayAtPosition(h.point, audioClip, hitPl && hitPl.IsMine ? 0 : 200);
                    }
                }

                //if (bs == null && !rocket)
                //{
                //    if (!lowQuality)
                //        _Game.Emit(h.point, h.normal, _Game.concrete);
                //    Destroy2(gameObject);
                //    break;
                //}
            }
        }

        if (wep.slide)
        {
            RaycastHit h2;
            if (Physics.Raycast(pos, -tr.up, out h2, 2, Layer.levelMask))
            {
                pos += Vector3.up * Time.deltaTime * 2;
            }
        }
        tr.position += vel;
    }
    void LoadCar()
    {
        if (m_Car)
            _Pool.Save(m_Car.gameObject);
        string path = cop ? "police" : owner.carSet.carName;
        Spawn spawnPos = GetSpawnStartPos();
        m_Car = _Pool.Load2(Resources.Load(path), spawnPos.pos, spawnPos.rot).GetComponent<CarControl>();
        if (m_Car.m_CarDamage.meshTest)
        {
            m_Car.m_CarDamage.meshTest.Reset(this == _Player);
            m_Car.rigidbody.velocity = m_Car.rigidbody.angularVelocity = Vector3.zero;
        }

        //m_Car = ((GameObject)Instantiate(Resources.Load(path), spawnPos.pos, spawnPos.rot)).GetComponent<CarControl>();
        m_Car.name = "Player Car " + pv.playerName;
        transformCar = m_Car.tr;
        rigidbody = m_Car.rigidbody;
        rigidbody.solverIterationCount = 6;
        m_CarSettings = m_Car.GetComponent<CarSettings>() as CarSettings;
        m_CarSound = m_Car.GetComponent<CarSound>() as CarSound;
        m_CarSettings.bypassABS = false;
        m_Car.pl = this;
        OnQualityChanged();
        var priority = this == _Player ? 100 : 130;
        foreach (var a in GetComponents<AudioSource>())
            a.priority = priority;
        foreach (var a in m_Car.audioSources)
            a.priority = priority;

        if (IsMine && !bot2)
            _Game.MainCamera.Target = m_Car.tr;
        AmplifyMotionEffect.RegisterRecursivelyS(m_Car.gameObject);
    }
 // Use this for initialization
 void Start()
 {
     car = GameObject.FindGameObjectWithTag ("PlayerGameController").GetComponent<CarControl>();
     srnTexture = GetComponent<screenTexture>();
 }
    // Use this for initialization
    void Start()
    {
        if(checkpointID == 23)
        {
            yellowCheckpassed = true;
            redCheckpassed = true;
            greenCheckpassed = true;
            blueCheckpassed = true;

        }
        else
        {
            yellowCheckpassed = false;
            redCheckpassed = false;
            greenCheckpassed = false;
            blueCheckpassed = false;
        }

        startLine = GetComponent<BoxCollider>();
        BlueCarScript = BlueCar.GetComponent<CarControl>();
        YellowCarScript = YellowCar.GetComponent<CarControl>();
        RedCarScript = RedCar.GetComponent<CarControl>();
        GreenCarScript = GreenCar.GetComponent<CarControl>();

        _cubeSize = colliderBox.size;
    }
 private void Awake()
 {
     car = GetComponent<CarControl>();
 }
 // Use this for initialization
 void Start()
 {
     car = GameObject.FindGameObjectWithTag ("PlayerGameController").GetComponent<CarControl>();
     UpdateSettings();
 }
Example #43
0
 void Awake()
 {
     instance = this;
 }
Example #44
0
File: Car.cs Project: marrony/ncar
    /*
     * motor:wheel
     * 1ª 3,596:1
     * 2ª 2,378:1
     * 3ª 1,531:1
     * 4ª 1,000:1
     * Ré 4,229:1
     * Diferencial 3,92:1
     */
    void Start()
    {
        Transform cg = transform.FindChild("CG");
        rigidbody.centerOfMass = cg.localPosition;

        /*turnLightRL = transform.Find("Model/maverick/RL_Turn_Light").gameObject;
        turnLightRR = transform.Find("Model/maverick/RR_Turn_Light").gameObject;*/
        machineGun = transform.Find("MachineGun").GetComponent<MachineGun>();
        Control = new CarControl();
    }
Example #45
0
 void Start()
 {
     m_Car = GetComponent <CarControl>();
 }
Example #46
0
 void Start()
 {
     networkViewer = this.GetComponent<NetworkView>();
     Audiosource = this.GetComponent<AudioSource> ();
     car = this.gameObject.GetComponent<CarControl> ();
 }