How to get splitted CFrame (Math scripting problem) [SOLVED]

lets say i got 2 objects, and i also have the mid point (position) where i want those two objects to appear but not at the same position but splited. you can see the picture:

2 Likes

another example for 3 objects:

2 Likes

what are you trying to achieve?

2 Likes

im trying to make npc arrival system similar to restaurant tycoon 2. when npcs arrive i want them to be positioned evenly

2 Likes

its as simple as adding all the vectors and dividing them by their amount

local function GetMidPointFromVectors(...)
   local Vectors = {...}
   local MidPoint = Vector3.zero
   
   for _, Vector in Vectors do
      MidPoint += Vector
   end

   return MidPoint / #Vectors
end

2 Likes
local function getSplittedPosition(xSize, amount, defaultPosition)
	local positionsX = {}
	local maxSize = xSize * (2 * amount)
	local xSizeForEachObject = maxSize / (amount - 1)

	for i = 0, amount - 1  do
		table.insert(positionsX, (defaultPosition.Z - (maxSize / 2)) + (xSizeForEachObject * i))
	end 

	return positionsX
end

after a bit of work i made it work
image

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.