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 MichaelTaylor3d · May 07, 2013 at 01:48 PM · cameratransformguitexture

Scale guiTexture with respect to camera distance

Id like my GUI Texture that is clamped to the 3d space of a gameobject, to scale with respect to the distance of the camera and that gameObject.

I cant seem to get my math right however. Farther distances should scale it smaller, and vice versa.

Any ideas?

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 gharbill · May 07, 2013 at 02:19 PM 0
Share

if you want to just fake perspective effect, why don't you just use a plane that always looks at camera?

avatar image MichaelTaylor3d · May 07, 2013 at 02:41 PM 0
Share

Thats my current implementation, but it decreases my frame rate dramatically when there are a lot of these in the scene at once, I was experimenting with the guitextures ins$$anonymous$$d and for whatever reason I dont get that framerate drop using them ins$$anonymous$$d.

avatar image robertbu · May 07, 2013 at 03:27 PM 0
Share

As an alternate solution, look at implementing a texture atlas for the textures on your plane.

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by gharbill · May 07, 2013 at 03:21 PM

Ok so in that case this seems to work:

 // Put this Script on your GUITexture
 // assign myCamera and myObject and you're good to go

 var myCamera : Transform;
 var myObject: Transform;
 private var viewPos: Vector3;
 
 private var ratio : float;
 private var distance : float;
 
 var distanceFactor : float = 1000;  //factor that needs to be configured 
                                     //to achieve desired result
                                     //with field of view = 60, value of 1000
                                     //seems to be a good number.
 
 function Start () {
 
 ratio = guiTexture.pixelInset.height/guiTexture.pixelInset.width; // fixes the ratio of the texture
 
 }
 
 function Update () {
 
 distance = (myCamera.position - myObject.position).magnitude;
 viewPos =  myCamera.camera.WorldToScreenPoint(myObject.position);

 guiTexture.pixelInset.width = (1/distance)*distanceFactor;
 guiTexture.pixelInset.height = ratio * guiTexture.pixelInset.width;

 //to keep the pivot of texture in center
 guiTexture.pixelInset.x = -(guiTexture.pixelInset.width /2) + viewPos.x;
 guiTexture.pixelInset.y = -(guiTexture.pixelInset.height /2) + viewPos.y;
 }

sure you have to manipulate it to make it work better hope it helps...

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 MichaelTaylor3d · May 07, 2013 at 04:42 PM 0
Share

Thanks!!!!

avatar image gharbill · May 07, 2013 at 05:00 PM 1
Share

I edited the code, now it will follow the object but the Texture is also drawn if you have 180 degree angle from it.

avatar image gharbill · May 07, 2013 at 05:17 PM 1
Share

Just remember to zero out position of your GUITexture ;)

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

13 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

Related Questions

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

How do I set a child object to not rotate if the parent WILL be rotating? 1 Answer

Transform.LookAt - wrong vector 4 Answers

Some GameObjects can't touch !!! 0 Answers

Why is my Camera rotation tilted after parenting it to head? 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