Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by adnan-zaman-13 · Jun 12, 2017 at 09:07 PM · cameragameobjectmeshverticesquad

Mesh's corners are not where it's supposed to be

My goal was to make a Quad that would take up the entire screen, regardless of where the camera moved, or zoomed in/zoomed out. I changed the corners of the Quad's mesh to be the corners of the visible game area...but the top right and left corners aren't where they're supposed to be.

I even tried spawning a test game object in the top-right (the same top-right coordinate that the Quad uses) and it actually did show up in the corner, unlike the Quad.

Any ideas what's going on?

     Ray topLeft,topRight,botLeft,botRight; //Rays shot out from camera to figure out the 4 corners for viewRect
     float distance; //Used to find out how far camera is from xy plane 
     Vector3 tl,tr,bl,br; //Coordinates of viewRect
     GameObject viewRect; //The rect that will represent the viewable part of the game
     Plane xy; // The xy plane
     Mesh mesh;
     Vector3[] vertices  = new Vector3[4];
     int[] tri = { 0, 3, 1, 3, 2, 1 };
 
 
     void Start () 
     {
         mesh = new Mesh();
         mesh.vertices = vertices;
         mesh.triangles = tri;
 
         Vector3 pos = Camera.main.transform.position;
         pos.z = 0;
         viewRect = GameObject.CreatePrimitive(PrimitiveType.Quad);
         viewRect.transform.position = pos;
         viewRect.tag = "CameraView";
 
         viewRect.GetComponent<MeshFilter>().mesh = mesh;
     
         xy = new Plane(new Vector3(0,0,-1), Vector3.zero);
         CurrentView();    
     }
 
 
     void LateUpdate () 
     {
         CurrentView();
     }
         
     //Calculates what is visible by the camera 
     void CurrentView()
     {
         //Shoots rays out of each corner of the screen
         topLeft = Camera.main.ScreenPointToRay(new Vector3(0,Screen.height,0));
         topRight = Camera.main.ScreenPointToRay(new Vector3(Screen.width,Screen.height,0));
         botLeft = Camera.main.ScreenPointToRay(new Vector3(0,0,0));
         botRight = Camera.main.ScreenPointToRay(new Vector3(Screen.width,0,0));
 
         //Calculates topleft coordinate
         xy.Raycast(topLeft, out distance);
         tl = topLeft.GetPoint(distance);
 
         //Calculates topright coordinate
         xy.Raycast(topRight, out distance);
         tr = topRight.GetPoint(distance);
 
         //Calculates bottomleft coordinate
         xy.Raycast(botLeft, out distance);
         bl = botLeft.GetPoint(distance);
 
         //Calculates bottomright  coordinate
         xy.Raycast(botRight, out distance);
         br = botRight.GetPoint(distance);
 
         vertices[0] = bl; vertices[1] = br; vertices[2] = tr; vertices[3] = tl;
         tri[0] = 0; tri[1] = 2; tri[2] = 1; tri[3] = 0; tri[4] = 3; tri[5] = 2;
         mesh.vertices = vertices;
         mesh.triangles = tri;
         viewRect.GetComponent<MeshFilter>().mesh = mesh;
 
         GameObject test = GameObject.CreatePrimitive(PrimitiveType.Quad);
         test.transform.position = tr;
     
 
 
     
     }

alt text

Screenshot of what I was talking about with the test game object.

question.jpg (35.0 kB)
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

112 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Build plane on quad of mesh with same vertices 1 Answer

Calculating mesh over GameObject scale 1 Answer

Move gameobject pivot 6 Answers

How to mark the vertices on a mesh and make the markers follow them as you apply transformations 0 Answers

Modifying plane to fit view frustrum issue 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges