Skip to main content
deleted 2 characters in body
Source Link
Kromster
  • 10.7k
  • 4
  • 55
  • 67

Here is the function to draw a triangle that represents the camera field of view in a minimap. The problem with this code snippet is that when I rotate up and down (Change the pitch of camera) the viewport triangle also rotates up/down. I

void makeViewPortCube()
{
    if (player.GetComponent<Camera>() == null)
    {
        // Debug.LogError("Please assing a Main Camera to Follow");
        return;
    }

    if (viewPortMesh == null)
    {
        viewPortGameobject = new GameObject();
        viewPortGameobject.AddComponent<MeshFilter>().mesh = makeStartingMeshForViewPort(2.0f, 2.0f);
        viewPortGameobject.AddComponent<MeshRenderer>().material = materiaForViewPortGameobject();
        viewPortGameobject.name = "View Port Object";
        viewPortMesh = viewPortGameobject.GetComponent<MeshFilter>().mesh;
        viewPortGameobject.layer = LayerMask.NameToLayer("MiniMap");
        viewPortGameobject.transform.position = new Vector3(viewPortGameobject.transform.position.x, /*transform.position.y-*/100, viewPortGameobject.transform.position.z);
    }

    // change vertices of the viewport
    Vector3[] aVertexList = viewPortMesh.vertices;

    if (stopRotation == false)
    {
        //Orignial
        aVertexList[1] = player.GetComponent<Camera>().ScreenToWorldPoint(new Vector3(Screen.width, 0, 10f));
        aVertexList[2] = player.GetComponent<Camera>().ScreenToWorldPoint(new Vector3(Screen.width, 0, player.GetComponent<Camera>().nearClipPlane));
        aVertexList[3] = player.GetComponent<Camera>().ScreenToWorldPoint(new Vector3(0, Screen.height / 4, player.GetComponent<Camera>().nearClipPlane));

        aVertexList[0] = player.GetComponent<Camera>().ScreenToWorldPoint(new Vector3(0, Screen.height / 4, 10f));

        for (int i = 0; i < 4; i++)
        {
            aVertexList[i].y = 3;
        }
    }

    viewPortMesh.vertices = aVertexList;
    viewPortMesh.RecalculateBounds();
}

Here is the function to draw a triangle that represents the camera field of view in a minimap. The problem with this code snippet is that when I rotate up and down (Change the pitch of camera) the viewport triangle also rotates up/down. I

void makeViewPortCube()
{
    if (player.GetComponent<Camera>() == null)
    {
        // Debug.LogError("Please assing a Main Camera to Follow");
        return;
    }

    if (viewPortMesh == null)
    {
        viewPortGameobject = new GameObject();
        viewPortGameobject.AddComponent<MeshFilter>().mesh = makeStartingMeshForViewPort(2.0f, 2.0f);
        viewPortGameobject.AddComponent<MeshRenderer>().material = materiaForViewPortGameobject();
        viewPortGameobject.name = "View Port Object";
        viewPortMesh = viewPortGameobject.GetComponent<MeshFilter>().mesh;
        viewPortGameobject.layer = LayerMask.NameToLayer("MiniMap");
        viewPortGameobject.transform.position = new Vector3(viewPortGameobject.transform.position.x, /*transform.position.y-*/100, viewPortGameobject.transform.position.z);
    }

    // change vertices of the viewport
    Vector3[] aVertexList = viewPortMesh.vertices;

    if (stopRotation == false)
    {
        //Orignial
        aVertexList[1] = player.GetComponent<Camera>().ScreenToWorldPoint(new Vector3(Screen.width, 0, 10f));
        aVertexList[2] = player.GetComponent<Camera>().ScreenToWorldPoint(new Vector3(Screen.width, 0, player.GetComponent<Camera>().nearClipPlane));
        aVertexList[3] = player.GetComponent<Camera>().ScreenToWorldPoint(new Vector3(0, Screen.height / 4, player.GetComponent<Camera>().nearClipPlane));

        aVertexList[0] = player.GetComponent<Camera>().ScreenToWorldPoint(new Vector3(0, Screen.height / 4, 10f));

        for (int i = 0; i < 4; i++)
        {
            aVertexList[i].y = 3;
        }
    }

    viewPortMesh.vertices = aVertexList;
    viewPortMesh.RecalculateBounds();
}

Here is the function to draw a triangle that represents the camera field of view in a minimap. The problem with this code snippet is that when I rotate up and down (Change the pitch of camera) the viewport triangle also rotates up/down.

void makeViewPortCube()
{
    if (player.GetComponent<Camera>() == null)
    {
        // Debug.LogError("Please assing a Main Camera to Follow");
        return;
    }

    if (viewPortMesh == null)
    {
        viewPortGameobject = new GameObject();
        viewPortGameobject.AddComponent<MeshFilter>().mesh = makeStartingMeshForViewPort(2.0f, 2.0f);
        viewPortGameobject.AddComponent<MeshRenderer>().material = materiaForViewPortGameobject();
        viewPortGameobject.name = "View Port Object";
        viewPortMesh = viewPortGameobject.GetComponent<MeshFilter>().mesh;
        viewPortGameobject.layer = LayerMask.NameToLayer("MiniMap");
        viewPortGameobject.transform.position = new Vector3(viewPortGameobject.transform.position.x, /*transform.position.y-*/100, viewPortGameobject.transform.position.z);
    }

    // change vertices of the viewport
    Vector3[] aVertexList = viewPortMesh.vertices;

    if (stopRotation == false)
    {
        //Orignial
        aVertexList[1] = player.GetComponent<Camera>().ScreenToWorldPoint(new Vector3(Screen.width, 0, 10f));
        aVertexList[2] = player.GetComponent<Camera>().ScreenToWorldPoint(new Vector3(Screen.width, 0, player.GetComponent<Camera>().nearClipPlane));
        aVertexList[3] = player.GetComponent<Camera>().ScreenToWorldPoint(new Vector3(0, Screen.height / 4, player.GetComponent<Camera>().nearClipPlane));

        aVertexList[0] = player.GetComponent<Camera>().ScreenToWorldPoint(new Vector3(0, Screen.height / 4, 10f));

        for (int i = 0; i < 4; i++)
        {
            aVertexList[i].y = 3;
        }
    }

    viewPortMesh.vertices = aVertexList;
    viewPortMesh.RecalculateBounds();
}
added 42 characters in body
Source Link

Here is the function to draw a triangle that represents the camera field of view in a minimap. The problem with this code snippet is that when I rotate up and down (Change the pitch of camera) the viewport triangle also also rotates up/down. I

void makeViewPortCube()
{
    if (player.GetComponent<Camera>() == null)
    {
        // Debug.LogError("Please assing a Main Camera to Follow");
        return;
    }

    if (viewPortMesh == null)
    {
        viewPortGameobject = new GameObject();
        viewPortGameobject.AddComponent<MeshFilter>().mesh = makeStartingMeshForViewPort(2.0f, 2.0f);
        viewPortGameobject.AddComponent<MeshRenderer>().material = materiaForViewPortGameobject();
        viewPortGameobject.name = "View Port Object";
        viewPortMesh = viewPortGameobject.GetComponent<MeshFilter>().mesh;
        viewPortGameobject.layer = LayerMask.NameToLayer("MiniMap");
        viewPortGameobject.transform.position = new Vector3(viewPortGameobject.transform.position.x, /*transform.position.y-*/100, viewPortGameobject.transform.position.z);
    }

    // change vertices of the viewport
    Vector3[] aVertexList = viewPortMesh.vertices;

    if (stopRotation == false)
    {
        //Orignial
        aVertexList[1] = player.GetComponent<Camera>().ScreenToWorldPoint(new Vector3(Screen.width, 0, 10f));
        aVertexList[2] = player.GetComponent<Camera>().ScreenToWorldPoint(new Vector3(Screen.width, 0, player.GetComponent<Camera>().nearClipPlane));
        aVertexList[3] = player.GetComponent<Camera>().ScreenToWorldPoint(new Vector3(0, Screen.height / 4, player.GetComponent<Camera>().nearClipPlane));

        aVertexList[0] = player.GetComponent<Camera>().ScreenToWorldPoint(new Vector3(0, Screen.height / 4, 10f));

        for (int i = 0; i < 4; i++)
        {
            aVertexList[i].y = 3;
        }
    }

    viewPortMesh.vertices = aVertexList;
    viewPortMesh.RecalculateBounds();
}

Here is the function to draw a triangle that represents the camera field of view. The problem with this code snippet is that when I rotate up and down the viewport triangle also rotates up/down.

void makeViewPortCube()
{
    if (player.GetComponent<Camera>() == null)
    {
        // Debug.LogError("Please assing a Main Camera to Follow");
        return;
    }

    if (viewPortMesh == null)
    {
        viewPortGameobject = new GameObject();
        viewPortGameobject.AddComponent<MeshFilter>().mesh = makeStartingMeshForViewPort(2.0f, 2.0f);
        viewPortGameobject.AddComponent<MeshRenderer>().material = materiaForViewPortGameobject();
        viewPortGameobject.name = "View Port Object";
        viewPortMesh = viewPortGameobject.GetComponent<MeshFilter>().mesh;
        viewPortGameobject.layer = LayerMask.NameToLayer("MiniMap");
        viewPortGameobject.transform.position = new Vector3(viewPortGameobject.transform.position.x, /*transform.position.y-*/100, viewPortGameobject.transform.position.z);
    }

    // change vertices of the viewport
    Vector3[] aVertexList = viewPortMesh.vertices;

    if (stopRotation == false)
    {
        //Orignial
        aVertexList[1] = player.GetComponent<Camera>().ScreenToWorldPoint(new Vector3(Screen.width, 0, 10f));
        aVertexList[2] = player.GetComponent<Camera>().ScreenToWorldPoint(new Vector3(Screen.width, 0, player.GetComponent<Camera>().nearClipPlane));
        aVertexList[3] = player.GetComponent<Camera>().ScreenToWorldPoint(new Vector3(0, Screen.height / 4, player.GetComponent<Camera>().nearClipPlane));

        aVertexList[0] = player.GetComponent<Camera>().ScreenToWorldPoint(new Vector3(0, Screen.height / 4, 10f));

        for (int i = 0; i < 4; i++)
        {
            aVertexList[i].y = 3;
        }
    }

    viewPortMesh.vertices = aVertexList;
    viewPortMesh.RecalculateBounds();
}

Here is the function to draw a triangle that represents the camera field of view in a minimap. The problem with this code snippet is that when I rotate up and down (Change the pitch of camera) the viewport triangle also rotates up/down. I

void makeViewPortCube()
{
    if (player.GetComponent<Camera>() == null)
    {
        // Debug.LogError("Please assing a Main Camera to Follow");
        return;
    }

    if (viewPortMesh == null)
    {
        viewPortGameobject = new GameObject();
        viewPortGameobject.AddComponent<MeshFilter>().mesh = makeStartingMeshForViewPort(2.0f, 2.0f);
        viewPortGameobject.AddComponent<MeshRenderer>().material = materiaForViewPortGameobject();
        viewPortGameobject.name = "View Port Object";
        viewPortMesh = viewPortGameobject.GetComponent<MeshFilter>().mesh;
        viewPortGameobject.layer = LayerMask.NameToLayer("MiniMap");
        viewPortGameobject.transform.position = new Vector3(viewPortGameobject.transform.position.x, /*transform.position.y-*/100, viewPortGameobject.transform.position.z);
    }

    // change vertices of the viewport
    Vector3[] aVertexList = viewPortMesh.vertices;

    if (stopRotation == false)
    {
        //Orignial
        aVertexList[1] = player.GetComponent<Camera>().ScreenToWorldPoint(new Vector3(Screen.width, 0, 10f));
        aVertexList[2] = player.GetComponent<Camera>().ScreenToWorldPoint(new Vector3(Screen.width, 0, player.GetComponent<Camera>().nearClipPlane));
        aVertexList[3] = player.GetComponent<Camera>().ScreenToWorldPoint(new Vector3(0, Screen.height / 4, player.GetComponent<Camera>().nearClipPlane));

        aVertexList[0] = player.GetComponent<Camera>().ScreenToWorldPoint(new Vector3(0, Screen.height / 4, 10f));

        for (int i = 0; i < 4; i++)
        {
            aVertexList[i].y = 3;
        }
    }

    viewPortMesh.vertices = aVertexList;
    viewPortMesh.RecalculateBounds();
}
Source Link

Show Camera field of view in minimap but without y axis rotation

Here is the function to draw a triangle that represents the camera field of view. The problem with this code snippet is that when I rotate up and down the viewport triangle also rotates up/down.

void makeViewPortCube()
{
    if (player.GetComponent<Camera>() == null)
    {
        // Debug.LogError("Please assing a Main Camera to Follow");
        return;
    }

    if (viewPortMesh == null)
    {
        viewPortGameobject = new GameObject();
        viewPortGameobject.AddComponent<MeshFilter>().mesh = makeStartingMeshForViewPort(2.0f, 2.0f);
        viewPortGameobject.AddComponent<MeshRenderer>().material = materiaForViewPortGameobject();
        viewPortGameobject.name = "View Port Object";
        viewPortMesh = viewPortGameobject.GetComponent<MeshFilter>().mesh;
        viewPortGameobject.layer = LayerMask.NameToLayer("MiniMap");
        viewPortGameobject.transform.position = new Vector3(viewPortGameobject.transform.position.x, /*transform.position.y-*/100, viewPortGameobject.transform.position.z);
    }

    // change vertices of the viewport
    Vector3[] aVertexList = viewPortMesh.vertices;

    if (stopRotation == false)
    {
        //Orignial
        aVertexList[1] = player.GetComponent<Camera>().ScreenToWorldPoint(new Vector3(Screen.width, 0, 10f));
        aVertexList[2] = player.GetComponent<Camera>().ScreenToWorldPoint(new Vector3(Screen.width, 0, player.GetComponent<Camera>().nearClipPlane));
        aVertexList[3] = player.GetComponent<Camera>().ScreenToWorldPoint(new Vector3(0, Screen.height / 4, player.GetComponent<Camera>().nearClipPlane));

        aVertexList[0] = player.GetComponent<Camera>().ScreenToWorldPoint(new Vector3(0, Screen.height / 4, 10f));

        for (int i = 0; i < 4; i++)
        {
            aVertexList[i].y = 3;
        }
    }

    viewPortMesh.vertices = aVertexList;
    viewPortMesh.RecalculateBounds();
}