|
| 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
|
  |
| Joined: 12 Sep 2011 |
| Total Posts: 1323 |
|
| |
|
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 |
|
|
|
| 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 |
|
|
|
| 21 Nov 2011 07:44 PM |
| Security? You don't need a high security to run table[math.floor(#table/2)]! |
|
|
| Report Abuse |
|
|
|
| 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 |
|
|
|
| 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 |
|
|
|
| 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 |
|
|
|
| 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 |
|
|
|
| 21 Nov 2011 08:19 PM |
I do agree.
But how would I also get the rotation? |
|
|
| Report Abuse |
|
|
|
| 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 |
|
|
|
| 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 |
|
|
|
| 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
|
  |
| 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 |
|
|