Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 cheezy94 · Dec 15, 2020 at 04:12 PM · cameratransform3dplanepixel

Pixel values of a plane (RectTransform)?

Here is a really simple video demo of tracking the top left pixel coordinates of a plane: https://streamable.com/xq5f2e

In my case, I have the top left corner of the screen to be origin (0,0); The values that are being output are the values that show far away the top left corner of the plane is from the top left corner of the game's screen. It seems though, after turning away from the plane after a certain angle, the coordinates of the top left corner get flipped and go from being negative to positive, whereas they should continue to be negative.

Here is the simple code to track the pixel values of the top left corner:

 private void FixedUpdate()
     {
         DisplayWorldCorners();
 
     }
 
     void DisplayWorldCorners()
     {
         rt = GetComponent<RectTransform>();
         Vector3[] v = new Vector3[4];
         rt.GetWorldCorners(v);
 
         Vector2 topLeft = Camera.main.WorldToScreenPoint(v[1]);
         Vector2 topRight = Camera.main.WorldToScreenPoint(v[2]);
         Vector2 bottomRight = Camera.main.WorldToScreenPoint(v[3]);
         Vector2 bottomLeft = Camera.main.WorldToScreenPoint(v[0]);
 
 
         topLeft.y = (Screen.height - topLeft.y);
         topRight.y = (Screen.height - topRight.y);
         bottomRight.y = (Screen.height - bottomRight.y);
         bottomLeft.y = (Screen.height - bottomLeft.y);
 
         text.text = "Top Left Coordinates: " + topLeft.ToString();
         Debug.Log("Top Left Coordinates: " + topLeft);
 
     }

Any know why the values drastically change from negative to positive? It seems like the values almost get inverted.

Comment
Add comment · Show 3
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
avatar image Zaeran · Dec 15, 2020 at 08:10 PM 0
Share

Could the point on the plane be behind the camera at this point? That could possibly be throwing some odd readings

avatar image cheezy94 Zaeran · Dec 15, 2020 at 10:58 PM 0
Share

Yeah, it is behind the camera which causes the value to approach a really large negative number and it eventually leads to an over flow (and makes it positive). Not sure how I could handle that and prevent the over flow for the top left corner's pixel value.

avatar image Zaeran cheezy94 · Dec 16, 2020 at 05:11 PM 0
Share

You can either do a check that the point is actually on the screen, or you can clamp the position to only valid coordinates, so that if it goes off screen, it'll treat it as if it's on the edge of the screen.

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

285 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 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 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

copying a 2d/3d plane/slab from one part of world and displaying it in another? 0 Answers

copy camera view to 2d panel and pixelate it 0 Answers

I need help with a model 0 Answers

How to get pixeldata from graphics.drawmesh? 0 Answers

Setting a cube to be exactly size of intersecting camera view plane 1 Answer


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