place an object between two vectors?
Hello there.
I'm playing around with vector3's. I got an object A placed somewhere in my level, and an Object B at another position.
Now I have a third object. I want this third object to move along the imaginary line between point A and point B using a float that goes from 0 to 1. 1 means it's at point B, 0 means it's at point A.
so a value of 0.5 should place the third object exactly in the middle of A and B.
It's some basic stuff, but I can't get it to work!!
Ideas? Thanks so much.
Answer by Hellium · Nov 17, 2017 at 07:01 PM
You are looking for the Lerp
(Linear Interpolation) function.
Vector3 pointA = objectA.transform.position // Position of objectA
Vector3 pointB = objectB.transform.position // Position of objectB
float a = 0.5f ; // A value between 0 and 1
Vector3 pointC = Vector3.Lerp( pointA, pointB, a ) ;
Here is the link to the documentation :
Your answer
![](https://koobas.hobune.stream/wayback/20220612142950im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Position is infinite 0 Answers
Unity Hanging when Changing a Vector3.x 2 Answers
How to make object land on certain point?,How to make object land on certain point?? 0 Answers
instantiate keeps repeating itself 0 Answers
How to Stack, Shuffle and deal cards 0 Answers