Answers for "How can I have a distance between 2 points = 0-1 (min = 0, max = 1) and in between is a decimal? [C#]"
http://answers.unity.com/questions/1543119/how-can-i-have-a-distance-between-2-points-0-1-min.html
The latest answers for the question "How can I have a distance between 2 points = 0-1 (min = 0, max = 1) and in between is a decimal? [C#]"Answer by Bunny83
http://answers.unity.com/answers/1543128/view.html
What you want is [InverseLerp][1] but for a Vector3. Unfortunately Vector3 doesn't have such a function. However if the point is exactly on the line between the two points you can use any of the 3 components as long as the components are not the same. So for example If you have (0,0,0) as start point and (10,0,5) as end point you can use x or z but not y as it is the same in start and end. So you could do
float t = Mathf.InverseLerp(start.x, end.x, point.x);
// or
float t = Mathf.InverseLerp(start.z, end.z, point.z);
<br>
However a more general approach would be projecting the relative vector from start to point onto the vector start to end.
Vector3 dir = end - start;
float t = Vector3.Dot(point - start, dir) / dir.sqrMagnitude;
Note that this generally works beyond the borders of start and end. So if "point" is before start the value will be negative, if it's behind end it will be larger than 1
[1]: https://docs.unity3d.com/ScriptReference/Mathf.InverseLerp.htmlThu, 16 Aug 2018 23:16:36 GMTBunny83Answer by Trevdevs
http://answers.unity.com/answers/1543122/view.html
if by "points" you mean Vectors (unity's term for positions in space. Then what you want to do it check the distances
Vector3 minPoint;
Vector3 maxPoint;
Vector3 thisPoint
float distanceFromMin = Vector3.Distance(thisPoint, minPoint);
distanceFromMin = Mathf.Round(distanceFromMin) this will give you a value 0.0f - 1.0f;
Just repeat this for the maxPoint as wellThu, 16 Aug 2018 23:06:12 GMTTrevdevs