✓ Accepted answer
Hello, I can help you, but only if you dont mind the rotation, because I never tested that and I am not sure how it would work. So, if I understand, there are 2 CFrames and you want something like middle between of them. I draw the situation on the paper, and I would calculate it like that:
local pos1 = CFrame1.Position
local pos2 = CFrame2.Position
local diffY = math.abs(pos1.Y - pos2.Y)
local targetY
if pos1.Y > pos2.Y then
targetY = pos2.Y + (diffY / 2)
else
targetY = pos1.Y + (diffY / 2)
end
local diffX = math.abs(pos1.X - pos2.X)
local targetX
if pos1.X > pos2.X then
targetX = pos2.X + (diffX / 2)
else
targetX = pos1.X + (diffX / 2)
end
local diffZ = math.abs(pos1.Z - pos2.Z)
local targetZ
if pos1.Z > pos2.Z then
targetZ = pos2.Z + (diffZ / 2)
else
targetZ = pos1.Z + (diffZ / 2)
end
local FINALPOSITION = Vector3.new(targetX, targetY, targetZ)
I tried to make it as easy as I could, I hope it will help! :D. Have a nice day.
Another probably easier way:
local pos1 = CFrame1.Position
local pos2 = CFrame2.Position
local FINALPOSITION = Vector3.new((pos1.X + pos2.X)/2, (pos1.Y + pos2.Y)/2, (pos1.Z + pos2.Z)/2)
1 comment
Finding the mean between two numbers is the same with CFrame. Add both the CFrame's together, (X+X, Y+Y, etc). Then divide the sum by 2, and that should be the centre between the two.