Something I did for not knowing something

Hello, a while ago (1 hour lol) I had made a code which calculated the midpoint of a point A and a point B
here is the code I have made:

function getMidlePoint(pA,pB)

	local calc = pA.Position - pB.Position
	local midle = pA.Position + (calc * -0.5)

	local vectorized = Vector3.new(midle.X,midle.Y,midle.Z)
	
	return vectorized

end

the problem is that I think there is a more efficient way to achieve that without creating a function from 0 but I have not managed to find anything that can do that (referring to doing something like Vector3.midpoint(pos1, pos2))
anyone know a better way to do this?

1 Like

I don’t think there is a function specifically for it, but this simplified code would also work:

function getMiddlePoint(pA,pB)
    return (pA+pB)/2
end
2 Likes
function getMiddlePoint(pA, pB)
  return (pA - pB)
end

wait are you tryna get midpoint between 2 positions?

As they mentioned this: Vector3.midpoint(pos1, pos2)), Im pretty sure they are.
Also, the problem with your script is that it only works if pA > pB, which is why my method was better

1 Like