Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do i find the average position of a group of objects?

I have a bunch of randomly dispersed parts, and i need the average position of them. I can't figure out how to do it with for loops.

1 answer

✓ Accepted answer

just do this loop through each one and add the vector3 pos together! might work not sure about the list.

local acc = vector3.new(0, 0, 0)
local partlist = {}
partlist.part1 = worspace.Part1 -- change these and add new ones if needed
partlist.Part2 = worspace.Part2
partlist.Part3 = worspace.Part3

for _,part in pairs(partlist) do
	acc = acc + part.Position
end
local avgx = acc.X / #partlist
local avgy = acc.y / #partlist
local avgz = acc.Z / #partlist

local avg = vector3.New(avgx, avgy, avgz)
print("finished!")

6 comments

0

Thank you alot lol

0

hey, can you please accept the answer? It would mean a lot.

0

First time i've ever used this site, i'll try to figure out how :p

0

Under the upvote and downvote theres a circle in a check, click it to accept the answer

0

There's nothing there

0

Just hover over the name and to the right I think

This discussion is preserved as it was. New answers, comments, and votes are closed.