Context: I'm making a pathfinding script and I want it to create a path. To get the size of the path brick I'm doing (Size1-Size2).magnitude But I dont know for the position, because if the values are (1,1,7) and (5,1,5) than it's going to end up negative although the mid point is positive.
Help?
There's another way you could do this, and it's called "linear interpolation", or lerping.
pointA = Vector3.new(234, 3456, 1) pointB = Vector3.new(34, 867, 1123) midpoint = pointA:Lerp(pointB, .5) print(midpoint)
The midpoint of 2 or more vectors is essentially the "average point" of the vectors.
Finding the midpoint of 2 or more vectors is exactly like finding the average of 2 or more numbers: you add all the numbers up, and divide them by the number of numbers there are.
So to find the midpoint of the vectors, it's just (Vector1 + Vector2 + ... + Vectorn) / n
In your case, it would be (Vector3.new(1, 1, 7) + Vector3.new(5, 1, 5)) / 2
Hope this helped!
If you want to perform pathfinding quickly, just use ROBLOX's PathfindingService, it's much easier.
However, if you insist on getting the midpoint of two vectors, the correct way of doing so is to add each vector up and divide by two.
Say if I had two variables, x and y. x has a value of Vector3.new(2,2,2) and y has a value of Vector3.new(1,2,3).
To get the midpoint of these two vector values, I add x and y up and then divide by two, like so:
local midpoint = (x + y) / 2 --Add up both vectors first because division comes before addition in BODMAS/BIDMAS/PEDMAS.
This is equivalent to the following:
local midpoint = (Vector3.new(2,2,2) + Vector3.new(1,2,3)) / 2
If you print out midpoint, it should print out 1.5, 2, 2.5.
I hope my answer helped you. If it did, be sure to accept.