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 » Scripters
Home Search
 

Re: How do I find the centre of a model?

Previous Thread :: Next Thread 
Waffloid is not online. Waffloid
Joined: 14 Jul 2011
Total Posts: 1606
25 Dec 2014 01:31 AM
I seriously have no clue how.

Follow me on Twitch! I'm WaffleRBLX.
Report Abuse
Goulstem is not online. Goulstem
Joined: 04 Jul 2012
Total Posts: 7177
25 Dec 2014 02:06 AM
Why do you need to?
Report Abuse
masterblokz is not online. masterblokz
Joined: 17 Nov 2010
Total Posts: 9517
25 Dec 2014 02:12 AM
model.PrimaryPart
Report Abuse
Goulstem is not online. Goulstem
Joined: 04 Jul 2012
Total Posts: 7177
25 Dec 2014 02:23 AM
^The primaryPart has to be set, and isn't always the centre.
Report Abuse
DavidBene is not online. DavidBene
Joined: 26 Nov 2014
Total Posts: 163
25 Dec 2014 02:29 AM
model:GetModelCFrame() is technically the easiest way to do it.

http://wiki.roblox.com/index.php?title=API:Class/Model/GetModelCFrame

But I would not recommend it, since the wiki says it's deprecated.
Report Abuse
Goulstem is not online. Goulstem
Joined: 04 Jul 2012
Total Posts: 7177
25 Dec 2014 02:46 AM
Just made dis for u:P

http://pastebin.com/Mwd023en
Report Abuse
128GB is not online. 128GB
Joined: 17 Apr 2014
Total Posts: 8056
25 Dec 2014 02:51 AM
@Goul
That doesn't work and since you put your x, y, and z tables outside the functions they will not empty them self after you run the function once so if you try and do it again it will break itself even more
Report Abuse
Goulstem is not online. Goulstem
Joined: 04 Jul 2012
Total Posts: 7177
25 Dec 2014 02:53 AM
I didn't make it perfect lol I just threw something together in 2 minutes.. i'm sure OP can edit it a bit if he needs to use it more than once.
Report Abuse
DavidBene is not online. DavidBene
Joined: 26 Nov 2014
Total Posts: 163
25 Dec 2014 02:53 AM
@Goulstem

Tested out your script with a part.

--------
part = Instance.new("Part",model.Parent)
part.CanCollide = false
part.Anchored = true
part.Size = Vector3.new(1,1,1)
part.Position = getModelCentre(model)
--------

It doesn't work properly.
Report Abuse
Goulstem is not online. Goulstem
Joined: 04 Jul 2012
Total Posts: 7177
25 Dec 2014 02:58 AM
http://pastebin.com/k9fHy3D7

Thar

also it rounds to nearest whole number, maybe that's why it wasn't accurate with one part.
Report Abuse
DavidBene is not online. DavidBene
Joined: 26 Nov 2014
Total Posts: 163
25 Dec 2014 03:04 AM
@Goulstem

Nope, your center is still way off. I noticed that you don't take a part's size into account. Remember each part's position is located at the part's center, and not at a corner of the part.
Report Abuse
DavidBene is not online. DavidBene
Joined: 26 Nov 2014
Total Posts: 163
25 Dec 2014 03:10 AM
The way I would probably do it is to find the lowest XYZ corner point of the model, then add (model:GetExtentsSize()/2) to it.
Report Abuse
DavidBene is not online. DavidBene
Joined: 26 Nov 2014
Total Posts: 163
25 Dec 2014 03:32 AM
I think this should work:

function compareVectors(v1,v2)
if v1.X < v2.X then v2 = Vector3.new(v1.X,v2.Y,v2.Z) end
if v1.Y < v2.Y then v2 = Vector3.new(v2.X,v1.Y,v2.Z) end
if v1.Z < v2.Z then v2 = Vector3.new(v2.X,v2.Y,v1.Z) end
return v2
end

function getCentre(model)
lowestPoint = nil
for index, child in pairs(model:GetChildren()) do
if child:IsA("BasePart") then
if lowestPoint == nil then
lowestPoint = child.Position-(child.Size/2)
else
lowestPoint = compareVectors(child.Position-(child.Size/2),lowestPoint)
end
end
end
return lowestPoint + (model:GetExtentsSize()/2)
end
Report Abuse
Waffloid is not online. Waffloid
Joined: 14 Jul 2011
Total Posts: 1606
25 Dec 2014 05:17 AM
Thanks.

Follow me on Twitch! I'm WaffleRBLX.
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • 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