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 salvolannister · Jun 28, 2020 at 04:27 PM · canvasworldspace

How to pop up a world canvas close to an object and in front of the camera view?

I'm trying to pop up a world canvas close to the object selected in VR and I get an optimal result doing like this:

  messageCanvas.SetActive(true);
         messageCanvas.transform.position = currentSelected.position;
         messageCanvas.transform.parent = currentSelected;
         messageCanvas.transform.rotation = Quaternion.identity;
         messageCanvas.transform.LookAt(mainCamera.transform.forward,Vector3.up);

Where messageCanvas is a gameobject containing a canvas with TextmeshPro and currentSelected is the GameObject Transform where I would like the canvas to be. I would like to have the canvas as if its forward vector was the same of my sight in order to read it better. This is the result that I have now:

canvas-Bug

What I have already tried is to use a Canvas Overlay and set is position with this function:

 messageCanvas.transform.position = Camera.main.WorldToScreenPoint(selectedObject.transform.position )

but the canvas get spawned really high in the world space and I can see it only from the Scene view.

What else can I try?

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
1
Best Answer

Answer by FeedMyKids1 · Jun 28, 2020 at 06:43 PM

 [SerializeField]  GameObject messageCanvas;
         [SerializeField] Transform currentSelected;
         [SerializeField] float distFromSelected = 5.0f;
         private void PlaceMessageCanvasAt(Transform currentSelected) 
         {
             messageCanvas.SetActive(true);
 
             Vector3 dirToCamera = currentSelected.position - Camera.main.transform.position;
 
             messageCanvas.transform.position = currentSelected.position - (dirToCamera.normalized * distFromSelected);
 
             messageCanvas.transform.LookAt(Camera.main.transform);
         }
Comment
Add comment · Show 3 · 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 FeedMyKids1 · Jun 28, 2020 at 06:48 PM 0
Share

You don't have to parent the canvas to the selected object.

If the selected object is moving you would need to call this method every time it moves.

The distance from selected is how far the message canvas is from the selected object (moving toward the camera) so a bigger distance means it's closer to the camera.

You could the distance differently by adding a vector3 offset so that it's above or off to the side of your selected transform.

The only rotation you have to do is with 'LookAt'.

This works with the game camera and would not work with your scene camera.

avatar image salvolannister · Jun 29, 2020 at 08:41 PM 0
Share

I did a little change because the canvas was showing at the correct position, but rotated of 180 degree, so I changed the last part in messageCanvas.transform.LookAt(Camera.main.transform.forward);. Thank you from the heart

avatar image FeedMyKids1 salvolannister · Jun 30, 2020 at 09:33 AM 0
Share

Oops. Sorry. I had tried it with a blank image so I didn't see that. Thanks for the heads up. Glad it works now.

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

139 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

Related Questions

How to stop collider from interfering with world space canvas? 1 Answer

World space buttons and preventing UI touch passthrough 0 Answers

3rd party UI - World Canvas or Screen Space Camera? 0 Answers

Canvas screen space to world space not working. 1 Answer

Move a 3d object from world space in the camera UI 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