- Home /
Position between objects, vector math.
Hi,
I need to do vector calculation but i don't know how to start that.
Green and red positions are known as Vector3 and "r" as a float value. I need to receive position of orange point.
My solution:
Vector3 redPos; //red dot
Vector3 greenPos; //green dot
float maxDis; // "r" value
//script on orange dot, change its position
transform.position = redPos;
transform.LookAt(greenPos);
transform.position += transform.forward * maxDis;
zadanie.jpg
(20.3 kB)
Comment
Best Answer
Answer by tanoshimi · Feb 28, 2015 at 02:18 PM
This is what Lerp is for:
Vector3 orangePos = Vector3.Lerp(redPos, greenPos, r);
Thanks, it was so easy with this function! But there is one mistake, not "r"
but r / Vector3.Distance(redPos, greenPos)
, so finally:
float L = r / Vector3.Distance(redPos, greenPos)
Vector3 orangePos = Vector3.Lerp(redPos, greenPos, L);
Your answer
![](https://koobas.hobune.stream/wayback/20220613184601im_/https://answers.unity.com/themes/thub/images/avi.jpg)