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
1
Question by Rustam-Ganeyev · Mar 18, 2013 at 12:37 PM · gameobjectscale

Make gameobject size always be the same

I have a 3d world, perspective camera, moving character and one gameobject, which I want to seem always the equal size on screen(for example, half of game screen size). If person is too far from that go, go's size should be larger, if too near, it's size should be smaller, so player will see it exactly the same size.

 void Update {
   //how to adjust it's size?
 }
Comment
Add comment · Show 6
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 AlucardJay · Mar 18, 2013 at 02:06 PM 1
Share

Store a reference to your player and the gameObject. From the transform.position of those objects, calculate a magnitude. Then use that magnitude as a modifier to the gameObjects scale.

avatar image Tarlius · Mar 18, 2013 at 02:47 PM 2
Share

What is the object? Have you considered an orthographic camera?

avatar image amphoterik · Mar 18, 2013 at 03:19 PM 1
Share

Is there a reason you need there to be a perspective camera? As Tarlius pointed out, an ortho camera would serve you better

avatar image Rustam-Ganeyev · Mar 18, 2013 at 05:57 PM 0
Share

No, I want exactly perspective camera, I want my object(it looks like a arrow) to be at the same place with the same size! Ortho-camera is impossible to use, because it's real 3d world.

avatar image AlucardJay · Mar 18, 2013 at 06:17 PM 1
Share

hmm, no votes on my suggestion, but have you thought about it / tried it? The scale is modified based on the distance between the objects, the distance is the magnitude of the difference between the 2 vectors. If this isn't resolved by tomorrow I shall write up a demonstration to prove the concept.

Show more comments

3 Replies

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

Answer by Loius · Mar 18, 2013 at 06:22 PM

 var size : float = (Camera.main.transform.position - transform.position).magnitude;
 transform.localScale = Vector3(size,size,size);

You'll probably want to multiply size by something, or make the object a child of an object scaled to keep its size where you want it.

Comment
Add comment · Show 1 · 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 Rustam-Ganeyev · Mar 18, 2013 at 06:34 PM 0
Share

yeah, i've done something like it:

 transform.localScale = Vector3(size,size,size) * $$anonymous$$UL;

but had problems, when character is too close to object. As a temporary solution I've done something like: if we are too close to object, show const size, otherwise show as you wrote. thank you for your solution!

avatar image
1

Answer by PAHeartBeat · Mar 18, 2013 at 03:55 PM

Hi Why you not try to follow your moving charter using camera (cam follow script), if camera and object will be at same distance every time, your character seem always the equal size.

you will find the script on unity communify

edit: you can also find that smooth follow script on FPS Controller which is inbuilt in Unity

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 Rustam-Ganeyev · Mar 18, 2013 at 06:04 PM 0
Share

You seem to misunderstand my question. I do have following camera on my character. And I have a gameobject which always stays on the same position(it's like an arrow pointer to player). I want to make this object always look the same size.

avatar image HamFar Rustam-Ganeyev · Aug 07, 2017 at 10:07 AM 0
Share

Have you figured this out?

avatar image
1

Answer by Neurolitic · Mar 20, 2014 at 03:14 PM

why not just make the gameobject a child of the main camera? .. fixed distance between the gameobject and the main camera means you do not need to scale the gameobject.

Comment
Add comment · 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

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

17 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

Related Questions

GameObject's scale gets 0 after being parented in editor 1 Answer

Can the insides of a gameObject affect its transform? 0 Answers

Whats the difference between transform.localScale.Set(2,1,1) and transfrom.localScale = new Vector3(2,1,1) 2 Answers

postion scale and rotation greyed out and not working 1 Answer

True scale of a visible GameObject with many childs 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