- Home /
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?
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.
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.
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.
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.
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
Your answer
Follow this Question
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