Beispiel #1
0
    /*
     * Este modo de cámara proporciona una vista aérea al jugador
     */
    void CinematicMode()
    {
        if (this.m_Circuit != null)
        {
            if (this.m_Direction.magnitude == 0)
            {
                this.m_Direction = new Vector3(0f, -1f, 0f);
            }

            int     segIdx;
            float   carDist;
            Vector3 carProj;

            m_Circuit.ComputeClosestPointArcLength(m_Focus.transform.position, out segIdx, out carProj, out carDist);

            Vector3 pathDir = -m_Circuit.GetSegment(segIdx);
            pathDir = new Vector3(pathDir.x, 0f, pathDir.z);
            pathDir.Normalize();

            this.m_Direction = Vector3.Lerp(this.m_Direction, pathDir, this.m_Following * Time.deltaTime);
            Vector3 offset = this.m_Direction * this.m_Distance;
            offset = new Vector3(offset.x, m_Elevation, offset.z);

            mainCamera.transform.position = m_Focus.transform.position + offset;
            mainCamera.transform.LookAt(m_Focus.transform.position);
        }
        else
        {
            mainCamera.transform.position = m_Focus.transform.position + m_offset;
            mainCamera.transform.LookAt(m_Focus.transform.position);
        }
    }
    void SavePlayer()
    {
        int        segId;
        Vector3    posProj;
        float      dist;
        float      arcLen = circuitController.ComputeClosestPointArcLength(transform.position, out segId, out posProj, out dist);
        RaycastHit hit;
        Vector3    up = Vector3.up;

        if (Physics.Raycast(posProj + Vector3.up * 0.1f, -Vector3.up, out hit, Mathf.Infinity))
        {
            posProj = hit.point + Vector3.up * 0.05f;
            up      = hit.normal;
        }
        transform.position = posProj;
        Vector3 dir = circuitController.GetSegment(segId);

        dir = Vector3.ProjectOnPlane(dir, up).normalized;
        transform.forward           = dir;
        m_Rigidbody.velocity        = Vector3.zero;
        m_Rigidbody.angularVelocity = Vector3.zero;
        m_PlayerInfo.SetSpeed(0);
        m_PlayerInfo.RpcResetCam();
    }