Esempio n. 1
0
    private void OnTriggerEnter(Collider other)
    {
        ArcadeKart kart = null;

        if (other.CompareTag("Player") || other.gameObject.layer == 13)
        {
            Debug.Log(other.gameObject);
            Debug.Log("COLISION");
            kart = other.GetComponentInParent <ArcadeKart>();
            if (ant)
            {
                kart.SetCanSlowSpeed(true);
                Destroy(this.gameObject);
            }
            else if (!shell)
            {
                kart.SetIfHit(true);
                kart.SetCanMove(false);
                Destroy(this.gameObject);
            }
            else if (shell && kart.gameObject == PlayerObjective.gameObject)
            {
                kart.SetIfHit(true);
                kart.SetCanMove(false);
                Destroy(this.gameObject);
            }
        }
    }
Esempio n. 2
0
    void Update()
    {
        // Reset the trigger flag
        if (BounceFlag)
        {
            BounceFlag = false;
        }
        Vector3 origin = transform.position;

        origin.y += HeightOffset;

        for (int i = 0; i < Angles.Length; i++)
        {
            Vector3 direction = GetDirectionFromAngle(Angles[i], Vector3.up, transform.forward);

            if (Physics.Raycast(origin, direction, out RaycastHit hit, RayDistance, CollisionLayer) && Time.time > resumeTime && !hasCollided && kart.LocalSpeed() > 0)
            {
                // If the hit normal is pointing up, then we don't want to bounce
                if (Vector3.Dot(hit.normal, Vector3.up) > 0.2f)
                {
                    return;
                }

                // Calculate the incident vector of the kart colliding into whatever object
                Vector3 incidentVector = hit.point - origin;

                // Calculate the reflection vector using the incident vector of the collision
                Vector3 hitNormal = hit.normal.normalized;
                reflectionVector   = incidentVector - 2 * Vector3.Dot(incidentVector, hitNormal) * hitNormal;
                reflectionVector.y = 0;

                kart.Rigidbody.velocity /= 2;
                // Apply the bounce impulse with the reflectionVector
                kart.Rigidbody.AddForce(reflectionVector.normalized * BounceFactor, ForceMode.Impulse);

                // Mark that the vehicle has collided and the reset time.
                kart.SetCanMove(false);
                BounceFlag = hasCollided = true;
                resumeTime = Time.time + PauseTime;

                if (BounceSound)
                {
                    AudioUtility.CreateSFX(BounceSound, transform.position, AudioUtility.AudioGroups.Collision, 0f);
                }
                return;
            }
        }

        if (Time.time < resumeTime)
        {
            Vector3    targetPos      = origin + reflectionVector;
            Vector3    direction      = targetPos - origin;
            Quaternion targetRotation = Quaternion.LookRotation(direction);
            kart.transform.rotation = Quaternion.Slerp(kart.transform.rotation, targetRotation, RotationSpeed * Time.deltaTime);
        }
    }
Esempio n. 3
0
    //Setup TrackerObject
    public void SetupAIKart()
    {
        input = GetComponent <AIInput>();
        ak    = this.GetComponent <ArcadeKart>();
        ak.SetCanMove(true);

        target = circuit.GetChild(currentWP).transform.position;

        tracker = new GameObject();
        tracker.transform.position = gameObject.transform.position;
        tracker.transform.rotation = gameObject.transform.rotation;
    }
Esempio n. 4
0
    void EndGame(bool win)
    {
        // unlocks the cursor before leaving the scene, to be able to click buttons
        Cursor.lockState = CursorLockMode.None;
        Cursor.visible   = true;

        m_TimeManager.StopRace();
        configuration.rankPlayer = FindRankIndex(playerKart) + 1;
        // Remember that we need to load the appropriate end scene after a delay
        gameState = win ? GameState.Won : GameState.Lost;
        endGameFadeCanvasGroup.gameObject.SetActive(true);
        if (win)
        {
            m_SceneToLoad          = winSceneName;
            m_TimeLoadEndGameScene = Time.time + endSceneLoadDelay + delayBeforeFadeToBlack;

            // play a sound on win
            var audioSource = gameObject.AddComponent <AudioSource>();
            audioSource.clip                  = victorySound;
            audioSource.playOnAwake           = false;
            audioSource.outputAudioMixerGroup = AudioUtility.GetAudioGroup(AudioUtility.AudioGroups.HUDVictory);
            audioSource.PlayScheduled(AudioSettings.dspTime + delayBeforeWinMessage);

            // create a game message
            winDisplayMessage.delayBeforeShowing = delayBeforeWinMessage;
            winDisplayMessage.gameObject.SetActive(true);
        }
        else
        {
            playerKart.SetCanMove(false);
            m_SceneToLoad          = loseSceneName;
            m_TimeLoadEndGameScene = Time.time + endSceneLoadDelay + delayBeforeFadeToBlack;

            // create a game message
            loseDisplayMessage.delayBeforeShowing = delayBeforeWinMessage;
            loseDisplayMessage.gameObject.SetActive(true);
        }
    }