- Home /
How do I get the Vector3 between two points 3/10 of the way?
Here's a little drawing of what I mean. I want to get the Vector3 of the green point. 3/10th of the way between the red and the blue point.
Comment
Sounds good, except that 3/10 != 10/3 ;)
Edit: Heh, he deleted his comment :/
Best Answer
Answer by S_Darkwell · Mar 17, 2015 at 11:06 PM
Vector3 pointGreen = Vector3.Lerp(pointRed, pointBlue, 0.3f);
Ah yes of course, Vector3.Lerp... It's often used only for smooth transitions but actually at is base is designed to do exactly what the OP needs! Upvoted.
Answer by Cherno · Mar 17, 2015 at 10:42 PM
This should work:
Vector3 redPos = new Vector3(0,0,0);
Vector3 bluePos = new Vector3(6,3,6);
Vector3 dir = bluePos - redPos;
float distance = Vector3.Distance(redPos , bluePos);
Vector3 oneThird = redPos + dir * (distance * 0.3f);
Interestingly enough, this is mostly the definition of Lerp (except dir isn't defined?) Anther way is: redPos+(bluePos-redPos)*0.3f;
You are right, I forgot to define dir, which is of course the direction vector.