• 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 FerroroshiX · Nov 29, 2018 at 05:28 PM · recttransformlocalposition

How can I adjust the edges of a RectTransform in order to put them exactly where I want in 3D local space?

Here is what I am trying to achieve by calculous:


What I want to achieve by calculous


It's a VR scene, with the head located at point O in the image. I want to assemble a list of text panels from top to bottom in a rounded fashion. The panels each have a RectTransform, and a local position relative to the head (O). I succeded in placing the center of the panels around like in the picture, but my problem is adjusting the edges (size of the RectTransform) of the panels.


I tried to get the corners of the panels in local space with the function RectTransform.GetLocalCorners, but I get incoherent positions: my x,y,z positions in local space of the yellow gizmos symbolizing the center of the panels are about [0, 0.7, 0.4] (and the second one is at [0, 0.57, 0.57]) and my corners are (-14, -25, 0), to (14, 25, 0) for the first panel. So my guess is they do not share the same reference.

I do actually have a scale to my rect transform (in order for the text to look good at the right size): the scale is (0.01, 0.01, 1). I think it might be the reason why I get my corners with absurd values. But maybe it's also because Unity gives me the corners relative to a 2D plane. I think it gives me the position of the corners relative to the yellow centers, but in 2D, and with another scale.


How can I adjust the edge of the RectTransforms in order to put the corners at the exact 3D local position (relative to O) I want?


Edit
I think my question wasn't clear enough on what I did and didn't do.


I already placed all my panels at the right places (local position), and already have the right rotations (local rotation). But my problem is finding the size of the "quad" (or in my case RectTransform, because I use TextMesh Pro) for my text.
I don't know the size because I change the number of panels and the distance to the observer programmatically (according to the text I want to display), so I want to calculate it so that each panel border touches exactly the next panel border.


Actually, I even have a formula for all my corners/size in 3D space, but my problem is converting it to "quad size" or "RectTransform size".


I don't know if it's possible.

panelsunity.jpg (691.5 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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by GamitusLabs · Nov 29, 2018 at 09:39 PM

It's my understanding that RectTransform is purely two-dimensional so you are going to get numbers that don't make sense for three-dimensional space. Instead, use the transform of the object which will have a three-dimensional position and rotation.


Assuming you know the distance from the camera to the transform, the size of the quad your text is on and the transform is always "looking at" the camera: you can calculate the angle between each consecutive quad using some basic trig. In the image below assume the following:


  1. B is the camera's origin

  2. C is the center of your quad


alt text


You could then get the angle at B (between vectors BC and BA) by the following equation:

< of B = ATAN( 4 / 7 )

If you then double that you have the angle between this quad and the next (assuming all quads are the same size).


If you want a better step-by-step on wth all that means, a quick google search turns up great resources like this: https://www.mathsisfun.com/algebra/trig-finding-angle-right-triangle.html

Comment
Add comment · Show 2 · Share
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 FerroroshiX · Nov 30, 2018 at 09:13 AM 0
Share

Thanks for your answer @GamitusLabs . Can you have a look at my edit please? I feel I didn't explain my problem clearly enough (or maybe I just don't understand the link between my clarified problem and your answer).

avatar image GamitusLabs FerroroshiX · Nov 30, 2018 at 01:45 PM 0
Share

ah, so the issue is actually getting the width/height (maybe RectTransform.GetWorldCorners?). previously sounded like it might the setup of a menu (or more likely i just read it too fast). unfortunately, i don't have the time to experiment with it at the moment, i'll check back later.

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

95 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

Related Questions

Accessing RectTransform Rotation? 1 Answer

SendMessage cannot be called during Awake, CheckConsistency, or OnValidate 0 Answers

How To Position Camera ViewPort Rect (Y) At The Bottom Of An Image & Size ViewPort Rect (H) With The Top Of The Image? 0 Answers

Reference Error on localPosition variable 1 Answer

parent and .localposition? 2 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