Comments and 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 comments and 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#]"Comment by Bunny83 on Bunny83's comment
http://answers.unity.com/comments/1543509/view.html
I don't quite get your question. Just imagine those values:
start = (10,5,3)
end = (20,0,3)
point = (12,4,3)
When you use the first method on either x or y it will return "0.2". $$anonymous$$eep in mind that the first method only works when the point is exactly on the line that connects start and end. The second method actually projects the point onto the line orthogonallyFri, 17 Aug 2018 23:27:21 GMTBunny83Comment by Broseph1010 on Broseph1010's answer
http://answers.unity.com/comments/1543471/view.html
With the first method, how could I get it to where everywhere in between is a decimal, right now, it is if it is at min, it is 0, and max it is 1, which is right, but there is no inbetween.Fri, 17 Aug 2018 20:39:37 GMTBroseph1010Comment by Bunny83 on Bunny83's answer
http://answers.unity.com/comments/1543131/view.html
I don't quite understand your logic here. distanceFromMin would just be the worldspace distance rounded to the nearest integer and not a decimal between 0 and 1.
<br>
So if "min" is (1,1,1), point is (5.5.5) and max is (10,10,10) your solution woulb give you the value "7" for "distanceFromMin " and a value of "9" for distanceFromMax.
<br>
Also note that [a vector][1] is not a "Unity term".
[1]: https://en.wikipedia.org/wiki/Euclidean_vectorThu, 16 Aug 2018 23:25:44 GMTBunny83Answer 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