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: Is it possible to get a model's position?

Previous Thread :: Next Thread 
PompeyTheGreat is not online. PompeyTheGreat
Joined: 10 Apr 2011
Total Posts: 5615
26 Nov 2011 07:08 PM
Title. If anyone knows how or can link me to a wiki page, then post away please.

#don't judge me
Report Abuse
swimguy777 is not online. swimguy777
Joined: 30 May 2009
Total Posts: 17092
26 Nov 2011 07:09 PM
model:GetModelCFrame()

-[::ƧѡÎḾḠΰῩ::]-[::Maker of stuff and Helper of Scripting::]-
Report Abuse
PompeyTheGreat is not online. PompeyTheGreat
Joined: 10 Apr 2011
Total Posts: 5615
27 Nov 2011 06:27 AM
@swim

And I could move a brick to the model like this;

cf = model:GetModelCFrame()
part.Position = Vector3.new(cf.x, cf.y, cf.z)

Correct?

#don't judge me
Report Abuse
NXTBoy is not online. NXTBoy
Joined: 25 Aug 2008
Total Posts: 4533
27 Nov 2011 06:40 AM
Not really. That will remove all rotation from the model. You'll want to use this (very old) script of mine: http://www.roblox.com/Model-CFraming-Script-item?id=21179422
Report Abuse
NXTBoy is not online. NXTBoy
Joined: 25 Aug 2008
Total Posts: 4533
27 Nov 2011 06:44 AM
That script is broken - that was pre `_G`-is-broken. Here's what you want:

    getCFrame = function(object)
        if object:isA("BasePart") then
            return object.CFrame
        elseif object:isA("Model") and object.PrimaryPart then
            return getCFrame(object.PrimaryPart)
        else
            for _, obj in ipairs(object:getChildren()) do
                local cf = getCFrame(obj)
                if cf then
                    return cf
                end
            end
        end
    end
    
    setCFrame = function(object, cframe)
        if object:isA("BasePart") then
            object.CFrame = cframe
        elseif object:isA("Model") then
            local center = getCFrame(object)
            if center == nil then return end
    
            local relativeCframes = {}
            for k, obj in ipairs(object:GetChildren()) do
                local cf = getCFrame(obj)
                if cf then
                    relativeCframes[k] = center:inverse() * cf
                end
            end
            for k, obj in ipairs(object:GetChildren()) do
                setCFrame(obj, cframe * relativeCframes[k])
            end
        end
    end
    
    _G.setCFrame = setCFrame
    _G.getCFrame = getCFrame
Report Abuse
1WOOF1 is not online. 1WOOF1
Joined: 03 May 2009
Total Posts: 20682
27 Nov 2011 06:46 AM
[ Content Deleted ]
Report Abuse
NXTBoy is not online. NXTBoy
Joined: 25 Aug 2008
Total Posts: 4533
27 Nov 2011 06:50 AM
Isn't that the goal here?

    setCFrame(workspace.MyModel, getCFrame(workspace.MyModel) * CFrame.new(50, 0, 0))

That would move the entire model (including submodels) 50 studs to the right/left
Report Abuse
1WOOF1 is not online. 1WOOF1
Joined: 03 May 2009
Total Posts: 20682
27 Nov 2011 06:51 AM
[ Content Deleted ]
Report Abuse
NXTBoy is not online. NXTBoy
Joined: 25 Aug 2008
Total Posts: 4533
27 Nov 2011 07:02 AM
Whoops
Report Abuse
PompeyTheGreat is not online. PompeyTheGreat
Joined: 10 Apr 2011
Total Posts: 5615
27 Nov 2011 07:21 AM
lol

Thanks bros.

#don't judge me
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