예제 #1
0
    internal override void Start()
    {
        base.Start();

        if (GetComponent<KartController>() != null)
        {
            kartController = GetComponent<KartController>();
            originalTorque = kartController.motorTorque;
            originalTopSpeed = kartController.topSpeed;

            kartController.motorTorque -= torqueDecrease;
            if (kartController.motorTorque <= 0)
                kartController.motorTorque = 0;

            kartController.topSpeed -= topSpeedDecrease;
            if (kartController.topSpeed <= 0)
                kartController.topSpeed = 0;
        }
        else if (GetComponent<NavMeshAgent>() != null)
        {
            minionAgent = GetComponent<NavMeshAgent>();
            originalTorque = minionAgent.acceleration;
            originalTopSpeed = minionAgent.speed;

            minionAgent.acceleration -= torqueDecrease;
            if (minionAgent.acceleration <= 0)
                minionAgent.acceleration = 0;

            minionAgent.speed -= topSpeedDecrease;
            if (minionAgent.speed <= 0)
                minionAgent.speed = 0;
        }
    }
예제 #2
0
    IEnumerator ResetCoroutine()
    {
        KartController kartController = GetComponent <KartController>();

        kartController.enabled = false;

        while (resetTimer > afterRespawnTime)
        {
            resetTimer -= Time.deltaTime;
            gameController.screenDarkenImage.color = new Color(0, 0, 0, 1f - ((resetTimer - afterRespawnTime) / resetTime));
            yield return(null);
        }
        Rigidbody rb = GetComponent <Rigidbody>();

        rb.MovePosition(transform.position = lasRespawnZone.transform.position);
        rb.MoveRotation(transform.rotation = lasRespawnZone.transform.rotation);
        rb.velocity        = Vector3.zero;
        rb.angularVelocity = Vector3.zero;

        CameraControllerCustom ccc = cameraRig.GetComponent <CameraControllerCustom>();

        if (ccc != null)
        {
            ccc.ReFocusOnTarget();
        }

        while (resetTimer > 0)
        {
            resetTimer -= Time.deltaTime;
            gameController.screenDarkenImage.color = new Color(0, 0, 0, (resetTimer / afterRespawnTime));
            yield return(null);
        }
        gameController.screenDarkenImage.color = new Color(0, 0, 0, 0);
        kartController.enabled = true;
    }
예제 #3
0
    void FixedUpdate()
    {
        KartController kc = GetComponent <KartController>();
        Rigidbody      rb = GetComponent <Rigidbody>();

        RaycastHit hit;

        grounded = Physics.Raycast(transform.position + transform.up * rayStartHeight, -transform.up,
                                   out hit, rayLength, onlyGroundMask);

        if (grounded)
        {
            // snap the rotation to match the ground normal (up to a certain angle)
            Quaternion rotation = Quaternion.LookRotation(hit.normal, transform.right)
                                  * Quaternion.Euler(180, -90, -90);
            if (Quaternion.Angle(rotation, transform.rotation) <= maxAngleChange)
            {
                transform.rotation = rotation;
            }

            // calculate speed in the forward direction
            float forwardSpeed = GetForwardSpeed();
            // calculate speed needed to get to desired speed and clamp accoring to accelerations
            float deltaSpeed;
            if (kc.acceleration > 0)
            {
                deltaSpeed = Mathf.Clamp(maxSpeed - forwardSpeed, 0, forwardsAcceleration * kc.acceleration);
            }
            else
            {
                deltaSpeed = Mathf.Clamp(minSpeed - forwardSpeed, backwardsAcceleration * kc.acceleration, 0);
            }

            rb.AddForce(transform.forward * deltaSpeed, ForceMode.Acceleration);

            // apply drag (different drag in different directions)
            Vector3 localVelocity = transform.InverseTransformDirection(rb.velocity);
            Vector3 localDrag     = Vector3.Scale(-localVelocity, localDragFactors);

            rb.AddForce(transform.TransformDirection(localDrag), ForceMode.Acceleration);

            // rotate kart depending on steering and speed
            float angle = kc.steering * Time.fixedDeltaTime * maxSteering
                          * speedToSteeringRatio.Evaluate(Vector3.Dot(rb.velocity, transform.forward) / maxSpeed);
            transform.Rotate(Vector3.up, angle);
        }
        else
        {
            // slowly rotate kart upright while in air
            Vector3 angles = transform.rotation.eulerAngles;
            angles = new Vector3(
                Mathf.LerpAngle(angles.x, 0, airRotationLerp * Time.fixedDeltaTime),
                angles.y,
                Mathf.LerpAngle(angles.z, 0, airRotationLerp * Time.fixedDeltaTime)
                );

            transform.rotation = Quaternion.Euler(angles);
        }
    }
 // Start is called before the first frame update
 void Start()
 {
     kc = GetComponent <KartController>();
     this.GetComponent <Ghost>().enabled = false;
     lastPos     = kc.rb.gameObject.transform.position;
     lastRot     = kc.rb.gameObject.transform.rotation;
     finishSteer = Random.Range(-1.0f, 1.0f);
 }
예제 #5
0
    private void Update()
    {
        KartController kc = GetComponent <KartController>();

        if (kc.restart)
        {
            ResetKart();
        }
    }
예제 #6
0
    void OnSceneGUI()
    {
        KartController kartController = target as KartController;

        Spline  spline       = kartController.playerController.spline;
        Vector3 kartPosition = kartController.transform.position;

        Handles.color = Color.cyan;
        Handles.DrawLine(kartPosition, spline.GetClosestPoint(kartPosition));
    }
예제 #7
0
    bool damaged;                                               // True when the player gets damaged.


    void Awake()
    {
        playerAudio    = GetComponent <AudioSource>();
        health         = 100;
        healthDecimal  = 0;
        healthDispText = GetComponent <TextMeshProUGUI>();
        playerMovement = GetComponent <KartController>();
        // Set the initial health of the player.
        currentHealth = startingHealth;
    }
예제 #8
0
 private void Awake()
 {
     kartController            = GetComponent <KartController>();
     rayCastSensors            = GetComponent <RayCastSensors>();
     rayCastSensors.RaysNumber = 9;
     rayCastSensors.rayLength  = 20f;
     int[] layersDim = new int[] { rayCastSensors.RaysNumber, 2 };
     aiModel   = new AIModel(layersDim);
     aiFitness = new AIFitness();
 }
예제 #9
0
 private void Awake()
 {
     controles          = GameObject.Find("MobileSingleStickControl");
     tacometro          = controles.transform.GetChild(7).gameObject;
     punteroGO          = tacometro.transform.GetChild(0).gameObject;
     punteroEjeZ        = punteroGO.transform;
     jugador            = FindObjectOfType <KartController>();
     _rigidbody         = jugador.rb;
     AnguloEulerInicial = punteroEjeZ.transform.localEulerAngles;
 }
예제 #10
0
    bool damaged;                                               // True when the player gets damaged.


    void Awake()
    {
        // Setting up the references.
        anim           = GetComponent <Animator>();
        playerAudio    = GetComponent <AudioSource>();
        playerMovement = GetComponent <KartController>();
        //playerShooting = GetComponentInChildren<PlayerShooting>();

        // Set the initial health of the player.
        currentHealth = startingHealth;
    }
예제 #11
0
 public override void OnJoinedRoom()
 {
     Destroy(playerGameObject);
     playerGameObject = PhotonNetwork.Instantiate(Path.Combine("Player"), spawnPoint.transform.position, spawnPoint.transform.rotation, 0);
     player           = playerGameObject.GetComponentInChildren <KartController>();
     player.enabled   = true;
     player.SetPlayerMaterial();
     gameCam.Follow = player.transform;
     gameCam.LookAt = player.transform;
     Debug.Log("Player instantiated");
 }
예제 #12
0
    int GetPlace(KartController KC)
    {
        int Place = 0;

        for (int i = 0; i < AllKarts.Count; i++)
        {
            if (AllKarts[i].Score >= KC.Score)
            {
                Place++;
            }
        }

        return(Place);
    }
예제 #13
0
    public void InitObjet(Vector3 pos, Quaternion q, string kartName)
    {
        GameObject kart = GameObject.Instantiate(Resources.Load(kartName), pos, q) as GameObject;

        //GameObject kart_angles = GameObject.Instantiate (Resources.Load("GameplayObject"), pos, q) as GameObject;
        kart.name   = kart.name.Split('(')[0];
        kc          = kart.GetComponent <KartController>();
        kart_script = kart.GetComponent <KartScript>();

        kart_script.SetKart(this);

        kc.setCoefficients(speedCoeff, turnCoeff);
        //kart_angles.GetComponent<Gameplay> ().SetKart (kart.transform);
    }
예제 #14
0
    internal override void Start()
    {
        base.Start();

        if (GetComponent<KartController>() != null)
        {
            kartController = GetComponent<KartController>();
            originalTorque = kartController.motorTorque;
            originalTopSpeed = kartController.topSpeed;

            kartController.motorTorque += torqueBoost;
            kartController.topSpeed += topSpeedBoost;
        }
    }
예제 #15
0
    internal override void Start()
    {
        base.Start();

        if (GetComponent <KartController>() != null)
        {
            kartController   = GetComponent <KartController>();
            originalTorque   = kartController.motorTorque;
            originalTopSpeed = kartController.topSpeed;

            kartController.motorTorque += torqueBoost;
            kartController.topSpeed    += topSpeedBoost;
        }
    }
예제 #16
0
    void OnTriggerEnter(Collider other)
    {
        // we need to look on the attachedRigidbody for the KartController, because the colliders are attached to a child
        // object.
        KartController kart = other.attachedRigidbody.GetComponent <KartController>();

        if (kart != null)
        {
            OnPickupCollected(kart);
        }

        // hide this item for a few seconds.
        Hide();
        Invoke("Show", 5.0f);
    }
예제 #17
0
    void OnCollisionEnter(Collision collisionInfo)
    {
        KartController kart = collisionInfo.gameObject.GetComponent <KartController>();

        if (kart != null)
        {
            if (kart.powerup == PickupType.NONE)
            {
                kart.powerup    = type;
                kart.pickupUses = (type == PickupType.TRIPLE_BOOST) ? 3 : 1;
            }

            lastPickedUpTime     = Time.time;
            meshRenderer.enabled = false;
            collider.enabled     = false;
        }
    }
    // Start is called before the first frame update
    void Start()
    {
        if (waypoint == null)
        {
            waypoint = GameObject.FindGameObjectWithTag("Waypoint").GetComponent <Waypoint>();
        }
        kc                    = GetComponent <KartController>();
        target                = waypoint.waypoints[currentWP].transform.position;
        nextTarget            = waypoint.waypoints[currentWP + 1].transform.position;
        totalDistanceToTarget = Vector3.Distance(target, kc.rb.gameObject.transform.position);

        tracker = GameObject.CreatePrimitive(PrimitiveType.Capsule);
        DestroyImmediate(tracker.GetComponent <Collider>());
        tracker.GetComponent <MeshRenderer>().enabled = false;
        tracker.transform.position          = kc.rb.gameObject.transform.position;
        tracker.transform.rotation          = kc.rb.gameObject.transform.rotation;
        this.GetComponent <Ghost>().enabled = false;
        finishSteer = Random.Range(-1.0f, 1.0f);
    }
예제 #19
0
    void Start()
    {
        allowInput = true;

        allowShoot      = true;
        allowDriving    = true;
        allowAiming     = true;
        allowSkillUsage = true;

        skillChanneling = false;
        skillAiming     = false;

        kartController = GetComponent <KartController>();
        kartShoot      = GetComponent <KartShoot>();
        kartGun        = GetComponent <KartGun>();
        kartCamera     = GetComponent <KartCamera>();
        pauseMenu      = FindObjectOfType <UIPauseMenu>();

        playerCamera = kartCamera.GetCamera();
    }
예제 #20
0
    internal override void Start()
    {
        base.Start();

        if (GetComponent <KartController>() != null)
        {
            kartController   = GetComponent <KartController>();
            originalTorque   = kartController.motorTorque;
            originalTopSpeed = kartController.topSpeed;

            kartController.motorTorque -= torqueDecrease;
            if (kartController.motorTorque <= 0)
            {
                kartController.motorTorque = 0;
            }

            kartController.topSpeed -= topSpeedDecrease;
            if (kartController.topSpeed <= 0)
            {
                kartController.topSpeed = 0;
            }
        }
        else if (GetComponent <NavMeshAgent>() != null)
        {
            minionAgent      = GetComponent <NavMeshAgent>();
            originalTorque   = minionAgent.acceleration;
            originalTopSpeed = minionAgent.speed;

            minionAgent.acceleration -= torqueDecrease;
            if (minionAgent.acceleration <= 0)
            {
                minionAgent.acceleration = 0;
            }

            minionAgent.speed -= topSpeedDecrease;
            if (minionAgent.speed <= 0)
            {
                minionAgent.speed = 0;
            }
        }
    }
예제 #21
0
    void FixedUpdate()
    {
        KartController kc   = GetComponent <KartController>();
        Kart           kart = GetComponent <Kart>();

        wheelRot += kart.GetForwardSpeed() * wheelSpeedFactor;

        for (int i = 0; i < allWheels.Length; i++)
        {
            GameObject obj = allWheels[i];
            obj.transform.localRotation = initialWheelRotations[i];
            obj.transform.Rotate(-Vector3.right, wheelRot);
        }

        float steeringOffset = kc.steering * steeringAngle;

        foreach (GameObject obj in frontWheels)
        {
            obj.transform.Rotate(Vector3.up, steeringOffset, Space.World);
        }
    }
예제 #22
0
 void OnCollisionEnter(Collision col)
 {
     if (col.gameObject.name == "PlayerOneKart" || col.gameObject.name == "PlayerTwoKart")
     {
         KartController kart    = col.gameObject.GetComponent <KartController>();
         ContactPoint   contact = col.contacts[0];
         Quaternion     rot     = Quaternion.FromToRotation(Vector3.up, contact.normal);
         Vector3        pos     = contact.point;
         Instantiate(Explosion, pos, rot);
         if (!kart.shieldEnabled)
         {
             kart.SubtractLife();
             col.rigidbody.AddExplosionForce(500000.0f, contact.point, 10.0f, 10000.0f);
             col.rigidbody.AddTorque(Vector3.up * 10000000.0f);
         }
         Destroy(gameObject);
     }
     else
     {
         Destroy(gameObject);
     }
 }
예제 #23
0
    public void HitCheckpoint(GameObject checkpointObject)
    {
        if (checkpoints[currentCheckpointIndex] == checkpointObject)
        {
            currentCheckpointIndex++;
            currentCheckpointIndex = currentCheckpointIndex % checkpoints.Length;
            if (currentCheckpointIndex == 1)
            {
                if (CurrentRound + 1 < numberOfRounds)
                {
                    CurrentRound++;
                }
                else
                {
                    // game finished
                    isTimerOn = false;

                    foreach (GameObject kart in karts)
                    {
                        KartController kartController = kart.GetComponent <KartController>();
                        kartController.enabled = false;
                    }

                    foreach (Animation anim in animationsOnFinish)
                    {
                        anim.Play();
                    }

                    foreach (Animator anim in animatorsPlayOnFinish)
                    {
                        anim.SetTrigger("play");
                    }
                }
            }
        }
    }
예제 #24
0
    // Use this for initialization
    void Start()
    {
        kc         = GetComponent <KartController>();
        kart_state = GetComponent <KartState>();


        foreach (Transform child in transform)
        {
            if (child.name == "kartSmoke")
            {
                smoke.Add(child.gameObject);
                continue;
            }
            if (child.name != "steering")
            {
                continue;
            }
            wheels["steering"] = child;
            foreach (Transform w in child.transform)
            {
                wheels[w.name] = w;
            }
        }
    }
예제 #25
0
    IEnumerator Grow()
    {
        float          TransitionSpeed = 0.1f;
        KartController KC           = this.transform.GetComponent <ItemInvoker>().KC;
        float          StartingMass = KC.GetComponent <Rigidbody>().mass;

        KC.GetComponent <Rigidbody>().mass = StartingMass * Scale;
        Vector3 StartingScale = Vector3.one;
        Vector3 BigScale      = new Vector3(Scale, Scale, Scale);

        float Alpha = 0f;

        while (Alpha < 1f)
        {
            Alpha += (Time.timeScale * TransitionSpeed);
            KC.transform.localScale = Vector3.Lerp(StartingScale, BigScale, GrowCurve.Evaluate(Alpha));
            yield return(null);
        }
        KC.transform.localScale = BigScale;

        yield return(new WaitForSeconds(Duration));

        KC.GetComponent <Rigidbody>().mass /= Scale;

        Alpha = 0f;
        while (Alpha < 1f)
        {
            Alpha += (Time.timeScale * TransitionSpeed);
            KC.transform.localScale = Vector3.Lerp(BigScale, StartingScale, GrowCurve.Evaluate(Alpha));
            yield return(null);
        }
        KC.transform.localScale = StartingScale;

        KC.ItemReference = null;
        Destroy(this.gameObject);
    }
예제 #26
0
    void Initialize()
    {
        GameObject[]          AllKartsObjects = GameObject.FindGameObjectsWithTag("Kart");
        List <KartController> AllKarts        = new List <KartController>();

        for (int i = 0; i < AllKartsObjects.Length; i++)
        {
            AllKarts.Add(AllKartsObjects[i].GetComponent <KartController>());
        }

        foreach (KartController K in AllKarts)
        {
            if (K.InControl == Target)
            {
                K.CameraEmpty = this.transform;
                Synced        = K;
            }
        }

        Map M = GameObject.FindWithTag("Map").GetComponent <Map>();

        switch (M.RaceData.PlayerCount)
        {
        case 1:
            switch ((int)Target - 1)
            {
            case 0: transform.GetChild(0).GetComponent <Camera>().rect = new Rect(0.0f, 0.0f, 1.0f, 1.0f); break;
            }
            break;

        case 2:
            switch ((int)Target - 1)
            {
            case 0: transform.GetChild(0).GetComponent <Camera>().rect = new Rect(0.0f, 0.5f, 1.0f, 0.5f); break;

            case 1: transform.GetChild(0).GetComponent <Camera>().rect = new Rect(0.0f, 0.0f, 1.0f, 0.5f); break;
            }
            break;

        case 3:
            switch ((int)Target - 1)
            {
            case 0: transform.GetChild(0).GetComponent <Camera>().rect = new Rect(0.0f, 0.5f, 1.0f, 0.5f); break;

            case 1: transform.GetChild(0).GetComponent <Camera>().rect = new Rect(0.0f, 0.0f, 0.5f, 0.5f); break;

            case 2: transform.GetChild(0).GetComponent <Camera>().rect = new Rect(0.5f, 0.0f, 0.5f, 0.5f); break;
            }
            break;

        case 4:
            switch ((int)Target - 1)
            {
            case 0: transform.GetChild(0).GetComponent <Camera>().rect = new Rect(0.0f, 0.5f, 0.5f, 0.5f); break;

            case 1: transform.GetChild(0).GetComponent <Camera>().rect = new Rect(0.5f, 0.5f, 0.5f, 0.5f); break;

            case 2: transform.GetChild(0).GetComponent <Camera>().rect = new Rect(0.0f, 0.0f, 0.5f, 0.5f); break;

            case 3: transform.GetChild(0).GetComponent <Camera>().rect = new Rect(0.5f, 0.0f, 0.5f, 0.5f); break;
            }
            break;
        }
    }
 void Start()
 {
     // keep a reference to the kart component
     kart = GetComponent <KartController>();
 }
예제 #28
0
 // Use this for initialization
 void Start()
 {
     kartController = gameObject.GetComponent<KartController>();
 }
예제 #29
0
 private void Start()
 {
     accuracy = 100.0f;
     car      = FindObjectOfType <KartController>();
 }
예제 #30
0
 protected abstract void OnPickupCollected(KartController kart);
예제 #31
0
    void Start()
    {
        allowInput = true;

        allowShoot = true;
        allowDriving = true;
        allowAiming = true;
        allowSkillUsage = true;

        skillChanneling = false;
        skillAiming = false;

        kartController = GetComponent<KartController>();
        kartShoot = GetComponent<KartShoot>();
        kartGun = GetComponent<KartGun>();
        kartCamera = GetComponent<KartCamera>();
        pauseMenu = FindObjectOfType<UIPauseMenu>();

        playerCamera = kartCamera.GetCamera();
    }
예제 #32
0
 private void Awake()
 {
     controller = GetComponent <KartController>();
 }
예제 #33
0
    // Use this for initialization
    void Start()
    {
        kart           = GetComponent <KartController>();
        steerSpeedCopy = kart.steerSpeed;
        ftCopy         = flashingTimer;
        lapManager     = GameObject.Find("Manager").GetComponent <LapsManager>();
        npcManager     = GameObject.Find("Manager").GetComponent <NewPlacementController>();
        //    checkPointPosition = GameObject.Find("RespawnPoint");
        lapNumber      = 1;
        steerAngleCopy = kart.maxSteerAngle;
        //  lockSteerTime = slickSpinOutTime;
        //Layer mask to ignore the kart.
        layerMask = 1 << LayerMask.NameToLayer("Vehicle");
        layerMask = ~layerMask;
        matCopy   = kartMat.material;
        wheelCopy = wheel1.material;
        //Acquire gamepad based on player number
        flashFull = true;

        greyBackDrop  = GameObject.Find("GreyBackDrop").GetComponent <Image>();
        pauseUI       = GameObject.Find("PauseUIPaused").GetComponent <Image>();
        pauseContinue = GameObject.Find("PauseUIContinue").GetComponent <Image>();
        pauseMenu     = GameObject.Find("PauseUIMainMenu").GetComponent <Image>();

        idleEngine     = GameObject.Find("EngineIdleSound").GetComponent <AudioSource>();
        kartCrash      = GameObject.Find("CrashSound").GetComponent <AudioSource>();
        gasLeak        = GameObject.Find("GasSound").GetComponent <AudioSource>();
        topEngineSpeed = GameObject.Find("TopSpeedSound").GetComponent <AudioSource>();
        explosion      = GameObject.Find("ExplosionSound").GetComponent <AudioSource>();

        for (int i = 1; i <= GamePadManager.Instance.ConnectedTotal(); ++i)
        {
            xbox_gamepad temppad = GamePadManager.Instance.GetGamePad(i);
            switch (playerNumber)
            {
            case 1:
                if (temppad.newControllerIndex == 1)
                {
                    gamepad = temppad;
                }

                break;

            case 2:
                if (temppad.newControllerIndex == 2)
                {
                    gamepad = temppad;
                }

                break;

            case 3:
                if (temppad.newControllerIndex == 3)
                {
                    gamepad = temppad;
                }

                break;

            case 4:
                if (temppad.newControllerIndex == 4)
                {
                    gamepad = temppad;
                }
                break;

            default:
                break;
            }
        }
    }
예제 #34
0
 private void Start()
 {
     car = FindObjectOfType <KartController>();
 }