// Update is called once per frame
 void Update()
 {
     if (!target && GameObject.FindGameObjectWithTag("Player"))
     {
         //Debug.Log("seteando player");
         target         = GameObject.FindGameObjectWithTag("Player").transform;
         car_controller = target.GetComponent <Car_Controller>();
     }
 }
Esempio n. 2
0
 void Start()
 {
     movement             = transform.parent.gameObject.GetComponent <Player_Movement>();
     cam_shaker           = transform.parent.gameObject.GetComponent <Camera_Shake>();
     carController        = transform.parent.gameObject.GetComponent <Car_Controller>();
     lapCheckPointCount   = 0;
     totalCheckPointCount = 0;
     playerNumber         = carController.playerNumber;
 }
Esempio n. 3
0
 void Start()
 {
     if (SceneManager.GetActiveScene().name == "Main_Menu")
     {
         mainMenu = true;
     }
     else
     {
         mainMenu = false;
     }
     horseClop     = HORSECLOP.NONE;
     carController = GetComponent <Car_Controller>();
     body          = GetComponent <Rigidbody2D>();
     if (carController.playerNumber == 1)
     {
         playerNumber = 1;
     }
     else if (carController.playerNumber == 2)
     {
         playerNumber = 2;
     }
     breaking        = false;
     speedMagnitude += acceleration;
     if (carController.playerNumber == 1)
     {
         goRight    = KeyCode.B;
         goLeft     = KeyCode.V;
         goLeftAlt  = KeyCode.Joystick1Button0;
         goRightAlt = KeyCode.Joystick1Button3;
         boost      = "Player1_Boost";
     }
     else
     {
         goRight    = KeyCode.Keypad2;
         goLeft     = KeyCode.Keypad1;
         goLeftAlt  = KeyCode.Joystick2Button0;
         goRightAlt = KeyCode.Joystick2Button3;
         boost      = "Player2_Boost";
     }
 }
 void Awake()
 {
     car_controller = GetComponent <Car_Controller>();
     randomValue    = Random.value * 100;
 }
Esempio n. 5
0
    // This function is responsible for spawning a car based on a Car_Class input. It will return a Car_Class
    // with references to the spawned objects of that car.
    public Car_Class SpawnCar(Car_Class car)
    {
        // If wheel amount is not affected by evolution, make sure every car has 2 wheels
        if (!main.wheelAmountAffectedByEvolution)
        {
            car.Wheels = car.Wheels.GetRange(0, 2);
            for (int i = 0; i < 2; i++)
            {
                if (car.Wheels.Count <= 1)
                {
                    car.Wheels.Add(new Wheel(new GameObject("Wheel WTF"), new Vector2(-1, -1), new Suspension(5, 0.5f), 1));
                }
            }
        }

        // Create a parent object that all other objects can be listed under in the hierarchy
        string carParentName = car.CarParent.name;

        Destroy(car.CarParent);
        if (carParentName == "")
        {
            carParentName = "Car";
        }
        car.CarParent = new GameObject(carParentName);
        car.DNA[0]    = car.CarParent;

        // Create the car body
        Destroy(car.Body);
        car.Body   = Instantiate(bodyPrefab, emptyVector3, emptyQuaternion, car.CarParent.transform);
        car.DNA[1] = car.Body;
        car.Body.transform.localScale = car.Size;

        // Make sure the body has a body tag, so we can exclude it from colliding with other cars.
        car.Body.layer = 8;

        // Determine the cars weight based on scale
        float mass = car.Size.x * car.Size.y * 100 * main.percentageOfCalculatedMass;

        if (mass < main.lowestMass)
        {
            mass = main.lowestMass;
        }
        car.Body.GetComponent <Rigidbody2D>().mass = mass;

        // Initialize the car controller component on the car body
        Car_Controller car_controller = car.Body.GetComponent <Car_Controller>();

        // Setup the engine
        car_controller.EngineSpeed       = car.Engine.EngineSpeed;
        car_controller.MaxMotorTorque    = car.Engine.MaxMotorTorque;
        car_controller.CarRotationTorque = car.Engine.CarRotationTorque;

        // Prepare the car driver
        car_controller.CorrectionCone   = car.Driver.CorrectionCone;
        car_controller.AccelerationCone = car.Driver.AccelerationCone;
        if (car.Driver.CorrectionCone != 0 || car.Driver.AccelerationCone != 0)
        {
            car_controller.hasDriver = true;
        }

        // Add the wheels
        float carLengthX = car.Body.GetComponent <SpriteRenderer>().bounds.size.x *(1 / car.Size.x) / 2;
        float carLengthY = car.Body.GetComponent <SpriteRenderer>().bounds.size.y *(1 / car.Size.y) / 2;

        foreach (Wheel wheel in car.Wheels)
        {
            // Get the position and instantiate the wheel object
            Vector3 wheelPos = new Vector3(Map(wheel.Position.x, -1, 1, carLengthX * -1, carLengthX), Map(wheel.Position.y, -1, 1, carLengthY * -1, carLengthY), 0);
            wheel.WheelGO = Instantiate(wheelPrefab, wheelPos, emptyQuaternion, car.CarParent.transform);

            // Add the wheel join
            WheelJoint2D wheelJoint = car.Body.AddComponent <WheelJoint2D>();
            wheelJoint.connectedBody = wheel.WheelGO.GetComponent <Rigidbody2D>();
            wheelJoint.anchor        = wheelPos;

            // Set wheels graphical size
            wheel.WheelGO.GetComponent <SpriteRenderer>().size = new Vector3(wheel.SizeX, wheel.SizeX);

            // Add wheel to the car tag, to avoid cars colliding with each other
            wheel.WheelGO.layer = 8;

            // Setup the suspension
            wheelJoint.suspension = new JointSuspension2D {
                frequency = wheel.Suspension.Stiffness, dampingRatio = wheel.Suspension.DampingRatio, angle = 90
            };
        }
        car.Body.GetComponent <Car_Controller>().wheels = car.Body.GetComponents <WheelJoint2D>();
        car.DNA[3] = car.Wheels;

        return(car);
    }
Esempio n. 6
0
    // Start is called before the first frame update
    void Start()
    {
        car_controller = Car.gameObject.GetComponent <Car_Controller>();

        InitServer();
    }
Esempio n. 7
0
 public void OnEnable()
 {
     m_target = (Car_Controller)target;
 }
    // Update is called once per frame
    void Update()
    {
        Debug.Log("X HEAD: " + head.transform.eulerAngles.x);
        Debug.Log("Y HEAD: " + head.transform.eulerAngles.y);
        Debug.Log("Z HEAD: " + head.transform.eulerAngles.z);
        if (!target && GameObject.FindGameObjectWithTag("Player"))
        {
            Debug.Log("seteando player");
            target         = GameObject.FindGameObjectWithTag("Player").transform;
            car_controller = target.GetComponent <Car_Controller>();
        }

        if (target && GameObject.FindGameObjectWithTag("Player"))
        {
            /**
             *	ALGORITMO PARA DOBLAR CON LA CABEZA
             */
            if (head.transform.eulerAngles.z > 15 && head.transform.eulerAngles.z < 90)
            {
                car_controller.steerInput = Mathf.Clamp(-1, -1, 1);
                Debug.Log("HEAD doblando izquierda");
            }
            else if (head.transform.eulerAngles.z < 345 && head.transform.eulerAngles.z > 270)
            {
                car_controller.steerInput = Mathf.Clamp(1, -1, 1);
                Debug.Log("HEAD doblando derecha");
            }
            else
            {
                car_controller.steerInput = Mathf.Clamp(0, -1, 1);
                Debug.Log("HEAD centrando");
            }

            /**
             *	ALGORITMO PARA ACELERAR O RETROCEDER CON LA CABEZA
             */

            if (head.transform.eulerAngles.x < 350 && head.transform.eulerAngles.x > 250)
            {
                //retrocede
                Debug.Log("HEAD retrocediendo");
                car_controller.motorInput = Mathf.Clamp01(0);
                car_controller.brakeInput = Mathf.Clamp01(1);
            }
            else if (head.transform.eulerAngles.x >= 0 && head.transform.eulerAngles.x < 100)
            {
                //acelera
                Debug.Log("HEAD acelerando");
                car_controller.motorInput = Mathf.Clamp01(1);
                car_controller.brakeInput = Mathf.Clamp01(0);
            }
            else
            {
                car_controller.motorInput = Mathf.Clamp01(0);
                car_controller.brakeInput = Mathf.Clamp01(0);
            }
        }


        //Debug.Log(IRDSStatistics.GetCurrentCar().GetPosition().x+"");

        //Debug.Log("x:"+GameObject.FindGameObjectWithTag("Player").transform.position.x);


        /*
         * MagnetSensor.OnCardboardTrigger += triggered;
         * if(carinput==null)carinput=GetComponent< IRDSCarControllInput > ();
         * if (Cardboard.SDK.CardboardTriggered)
         * {
         *      Debug.Log("trigger Update");
         *      carinput.setHandBrakeInput (1);
         *      carinput.setBrakeInput(1);
         *
         *
         *
         * }
         * if (Cardboard.SDK.Triggered)
         * {
         *      Debug.Log("trigger Update");
         *      carinput.setHandBrakeInput (1);
         *      carinput.setBrakeInput(1);
         *
         *
         * } */
        //Debug.Log (""+carinput.GetPosition);
        //transform.position = carinput.GetPosition;
    }
Esempio n. 9
0
    // Update is called once per frame
    void Update()
    {
        //Debug.Log ("X HEAD: "+head.transform.eulerAngles.x);
        //Debug.Log ("Y HEAD: "+head.transform.eulerAngles.y);
        //Debug.Log ("Z HEAD: "+head.transform.eulerAngles.z);
        if (!target && GameObject.FindGameObjectWithTag("Player"))
        {
            //Debug.Log("seteando player");
            target         = GameObject.FindGameObjectWithTag("Player").transform;
            car_controller = target.GetComponent <Car_Controller> ();
        }

        if (target && GameObject.FindGameObjectWithTag("Player"))
        {
            /**
             *    ALGORITMO PARA DOBLAR CON LA CABEZA
             */
            if (head.transform.eulerAngles.z > 5 && head.transform.eulerAngles.z < 90)
            {
                //formula= 90=1
                //            angulo=x
                // angulo/90

                car_controller.steerInput = Mathf.Clamp(-(head.transform.eulerAngles.z / 90), -1, 1);
                //Debug.Log("HEAD doblando izquierda");
            }
            else if (head.transform.eulerAngles.z < 359 && head.transform.eulerAngles.z > 270)
            {
                car_controller.steerInput = Mathf.Clamp((head.transform.eulerAngles.z - 360) / (-90), -1, 1);
                //Debug.Log("HEAD doblando derecha");
            }
            else
            {
                car_controller.steerInput = Mathf.Clamp(0, -1, 1);
                //Debug.Log("HEAD centrando");
            }

            /**
             *    ALGORITMO PARA ACELERAR O RETROCEDER CON LA CABEZA
             */

            if ((head.transform.eulerAngles.x < 360 && head.transform.eulerAngles.x > 160) ||
                (head.transform.eulerAngles.x >= 0 && head.transform.eulerAngles.x < 20))
            {
                //retrocede
                //Debug.Log("HEAD acelerando");
                car_controller.motorInput = Mathf.Clamp01(1);
                car_controller.brakeInput = Mathf.Clamp01(0);
            }
            else if (head.transform.eulerAngles.x >= 20 && head.transform.eulerAngles.x < 150)
            {
                //acelera
                //Debug.Log("HEAD retrocediendo");
                car_controller.motorInput = Mathf.Clamp01(0);
                car_controller.brakeInput = Mathf.Clamp01(1);
            }
            else
            {
                car_controller.motorInput = Mathf.Clamp01(0);
                car_controller.brakeInput = Mathf.Clamp01(0);
            }
            if (Input.GetKey(KeyCode.Return) && RaceManager.instance)
            {
                if (RaceManager.instance.raceStarted)
                {
                    car_controller.Respawn();
                }
            }
        }
    }
Esempio n. 10
0
 void Awake()
 {
     car_controller = GetComponent <Car_Controller>();
 }