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 pretender · Nov 06, 2010 at 02:55 PM · camerascalevectorline

change the length of the vector

hi, i tried to change the length of the vector using Vector3.Scale and it seems that it didnt work, here is the code is used:

//CALCULATE THE END POINT OF THE LINE
MicroLabel[i].endPoint=direction+MicroLabel[i].startPoint;  
MicroLabel[i].endPoint=Vector3.Scale(MicroLabel[i].endPoint,Vector3(0.2,0.2,0.2));

it messes up the direction. so the question is how to make vector smaller or bigger in length and not mess the direction in the process? i cant seem to figure that out. also i would like to be somehow connected to the camera.distance so that labels and lines stays inside the viewport..any ideas?

thanks!

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

Answer by SteveFSP · Nov 06, 2010 at 03:31 PM

Based on the nomenclature you are using (start point, end point), it appears you are scaling the wrong value. Scaling the direction is what you should be doing. Something like:

Vector3 scaledDirection =Vector3.Scale(direction,Vector3(0.2,0.2,0.2));
MicroLabel[i].endPoint=scaledDirection+MicroLabel[i].startPoint;

In general, scaling is used on direction vectors rather than vectors which represent points.

I'm afraid that I don't have complete answer for how to scale a line's length to keep it in the view port. There was a case where I needed to scale the width of a LineRenderer based on the camera's distance from it. In that case, I obtained the distance of the camera from the target, then derived a scale based on that distance. E.g. scaleToApply = distanceToTarget * constantScalingFactor. Rudimentary, but it worked in my case.

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 Bampf · Nov 06, 2010 at 03:46 PM 2
Share

Also, to scale a vector uniformly, you can simply multiple by the amount. Vector3 scaledDirection = direction * 0.2;

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

No one has followed this question yet.

Related Questions

Change UI scale in relation to 3D camera 0 Answers

Show squares in the camera 0 Answers

Unrealistic size of sun, viewed from earth 2 Answers

Colliders won't work 0 Answers

Camera settings for viewing any model like the Unity Preview 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