generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripting Helpers
Home Search
 

Re: Finding the center of a table of parts?

Previous Thread :: Next Thread 
cjcool12345 is not online. cjcool12345
Joined: 28 Jan 2010
Total Posts: 606
21 Nov 2011 07:35 PM
How would I find the center of a group of parts that are all stored in a table?
Report Abuse
Lowcart is not online. Lowcart
Joined: 12 Sep 2011
Total Posts: 1323
21 Nov 2011 07:36 PM
[ Content Deleted ]
Report Abuse
smurf279 is not online. smurf279
Joined: 15 Mar 2010
Total Posts: 6871
21 Nov 2011 07:37 PM
cant think of much off the top of my head but you'd probably have to insert the parts into the table in a certain order or looked through the position of every part in the table to find the center.
Report Abuse
cjcool12345 is not online. cjcool12345
Joined: 28 Jan 2010
Total Posts: 606
21 Nov 2011 07:42 PM
Well, I don't have very many resources to work with in the environment context that will be doing this, but I do have a higher security context.
I think I have a security context of one more then the command line... but I'm not sure.

Any built in functions that I could use?
Report Abuse
kingkiller1000 is not online. kingkiller1000
Joined: 12 Dec 2008
Total Posts: 26415
21 Nov 2011 07:44 PM
Security? You don't need a high security to run table[math.floor(#table/2)]!
Report Abuse
cjcool12345 is not online. cjcool12345
Joined: 28 Jan 2010
Total Posts: 606
21 Nov 2011 07:46 PM
I'm trying to find the center (in a CFrame value) of the group of parts (BaseParts).
Not a specific part.
Report Abuse
crazypotato4 is not online. crazypotato4
Joined: 22 Feb 2010
Total Posts: 20000
21 Nov 2011 07:54 PM
for the average:

total = Vector3.new()
table.foreach(parts), function(_,v) total = total + v.Position end)
print(total/#parts)

for the center:

local top, bottom
table.foreach(parts, function(_,v) top = Vector3.new((top and top.x > v.Position.x) and top.x or v.x, (top and top.y > v.Position.y) and top.y or v.y, (top and top.z > v.Position.z) and top.z or v.z); bottom = Vector3.new((top and top.x < v.Position.x) and top.x or v.x, (top and top.y < v.Position.y) and top.y or v.y, (top and top.z < v.Position.z) and top.z or v.z); end)
print(top:Lerp(bottom,0.5))

just because i was bored

they should work i think
Report Abuse
cjcool12345 is not online. cjcool12345
Joined: 28 Jan 2010
Total Posts: 606
21 Nov 2011 08:02 PM
Would it work to just run a loop that places clones of all the parts into a model instance and then use the GetModelCFrame method?
Report Abuse
crazypotato4 is not online. crazypotato4
Joined: 22 Feb 2010
Total Posts: 20000
21 Nov 2011 08:06 PM
I suppose so, but that would be very inefficient since it would have to create lots of new instances, which is far more complex than just making some new Vector3s and doing a bit of math. Ultimately, the way I showed is probably the best way to do it, if you're just looking for position. If you absolutely need rotation, then there's probably some way to calculate it exactly how Roblox does it, I just don't know how.
Report Abuse
cjcool12345 is not online. cjcool12345
Joined: 28 Jan 2010
Total Posts: 606
21 Nov 2011 08:19 PM
I do agree.

But how would I also get the rotation?
Report Abuse
cjcool12345 is not online. cjcool12345
Joined: 28 Jan 2010
Total Posts: 606
21 Nov 2011 08:26 PM
I really need to read all of each comment...

Also, is there any way to see the built-in methods code?
Maybe if I see how the method does it then I can remake the method for just a table instead of a model.
Report Abuse
kingkiller1000 is not online. kingkiller1000
Joined: 12 Dec 2008
Total Posts: 26415
21 Nov 2011 08:29 PM
No, there's no way to see built-in methods code, especially that some of them are in C, not Lua.
Report Abuse
cjcool12345 is not online. cjcool12345
Joined: 28 Jan 2010
Total Posts: 606
21 Nov 2011 08:35 PM
Well looks like the model making method wins (tho inefficiency) :/

Maybe one day I will find a way to see the built-in methods (I can't seem to write C, but I can read it).
Report Abuse
pwnedu46 is not online. pwnedu46
Joined: 23 May 2009
Total Posts: 7534
21 Nov 2011 10:03 PM
Lua source code is available for FREEEEEE. I'm not sure how you'd get Roblox's source code. :\

lua dawt org slash ftp


----------
    ~ pwendu46 ~
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image