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
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);
}
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.