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 MountDoomTeam · Sep 26, 2012 at 06:14 AM · vector3axisline

Use yAxis as a Vector3(0,0,yAxis) paramenter?

how do i make something vary according to world height, for example a spaceship that thrusts progressively less from world 0 to world 1000 y axis, or to write a phrase like

 balloon.transform.localScale = Vector 3(yaxis,yaxis,yaxis)

is it also possible to change size according to position in a local object?

i.e.

 aliceInWonderland.transform.localScale = Vector3( roomCubeXAxis,roomCubeXAxis,roomCubeXAxis)

so that alice in wonderland grows smaller as she walks forwards in a cube?

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

3 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by shaderop · Sep 26, 2012 at 08:08 AM

Just set whatever value you want to change the inverse exponent of the distance from the world's origin. For example, to make get smaller as it moves away from the world center, you can do something like this:

 // Make sure to store the object's original scale in a variable
 // in your Start function

 private Vector3 originalScale;
 void Start()
 {
     originalScale =  = this.transform.localScale;
 }

 void Update()
 {
     float scaleFactor = Mathf.Exp(-this.transform.position.magnitude);

     float xScale = originalScale.x * scaleFactor;
     float yScale = originalScale.y * scaleFactor;
     float zScale = originalScale.z * scaleFactor;

     this.transofrm.localScale = new Vector3(xScale, yScale, zScale);
 }

I have't tested it, but it should do the trick.

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
avatar image
1

Answer by fafase · Sep 26, 2012 at 07:08 AM

You could use the distance between the two object and use this as a multiplier.

  localScale = distance*ratio;

As you get closer distance gets smaller and your ratio is for instance 0.1=>

10m => 10*0.1 = 1

9m => 9*0.1 = 0.9 shrinking

and so on

obviously you would trigger this with a trigger collider so that it does not happen everywhere in the world, only when you enter a zone around the object.

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 MountDoomTeam · Sep 26, 2012 at 08:03 AM 0
Share

Thanks! that seems like the best workaround for it! after you say that i found there is also plane.distance to find the distance from a plane defined with 3 points.

avatar image fafase · Sep 26, 2012 at 08:19 AM 0
Share

The advantage of using a trigger box or sphere is that if you are outside of it, you do not use any computation to check for distance. You could use.

 Vector3.Distance(position, object.position);

but that would be computed every frame. The trigger is done by the Physics engine so you do not need worry about it.

avatar image
0

Answer by MountDoomTeam · Nov 07, 2012 at 07:15 PM

also could have done

      yaxis = baloon.transform.position.y
      balloon.transform.localScale = Vector3(yaxis,yaxis,yaxis); 

There is another way that I just found for something similar by making a plane and then using the distance to plane function:

     var flat: Plane;
     flat.Set3Points(Vector3.zero, Vector3(1, 0, 1), Vector3(1, 0, 2));
     var  distance: float;
     distance= flat.GetDistanceToPoint (Vector3(2,4,5));
     print( "distance"+distance);
 

so in this case, any time the distance-Vector3 is called it will give the altitude relative to a flat plane corresponding to the XZ axis.

Keywords-distance from 2d plane to point

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

10 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

Related Questions

Accouting for random rotations in Rotate Around 1 Answer

Problem with Vector3 direction and axises. 3 Answers

Instantiate objects at random positions on axis 2 Answers

Get Direction based on Velocity 0 Answers

How to get axially symmetric vector3? 3 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