Home > Software engineering >  How to Gradually Increase a Number from 0 to 60 as One GameObject gets closer to another GameObject
How to Gradually Increase a Number from 0 to 60 as One GameObject gets closer to another GameObject

Time:10-23

Have Script which calculates the distance with Vector3.Distence.

what i want is to increase a Number from 0 to 60 based on how close one gameobject is to the other gameobject. Any help is appreciated.

CodePudding user response:

Basic maths:

Number = 60/(1 Distance);

When distance is infinity, it returns 0.
When distance is 0, it returns 60.

Edit (with comment informations):

Number = 15*(4-Min(4, Distance));

When distance is greater than 4, it returns 0. When distance is 0, it returns 60.

  • Related