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?
aliceInWonderland.transform.localScale = Vector3( roomCubeXAxis,roomCubeXAxis,roomCubeXAxis)
so that alice in wonderland grows smaller as she walks forwards in a cube?
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;
originalScale = = this.transform.localScale;
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.
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.
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));
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