Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

[UNANSWERED] Retaining model rotation when moving via primary cframe?

Asked by
npott13 23
7 years ago
Edited 7 years ago

How can i retain the model rotation when moving model using SetPrimaryCFrame?

Because whenever i rotate the model by any degree and move it, the model don't retain the rotation i set. This is a problem i'm currently have with my model dragging script...

The rotation script.

mouse.KeyDown:connect(function (key) -- Safe rotation
    pcall (function()
function rotateMod(mod,rotation)

    if key == "r" and _G.target:FindFirstChild("CanRotate") then 
local center = mod:GetModelCFrame()
    local parts ={}
    local function scan(parent)
        for _,obj in pairs(parent:GetChildren()) do
            if (obj:IsA("BasePart")) then
                table.insert(parts,obj)

            end
            scan(obj)
        end
    end
    scan(mod)
    for _,part in pairs(parts) do
        part.CFrame = (center*rotation*(center:inverse()*part.CFrame))
    end
end
end

rotateMod(_G.target,CFrame.Angles(0,math.rad(10),0))
end)
end)

****UPDATE****

Abstract_Life answer doesn't work it shows error . This is the output, i am so stupid i forgot i had pcall function on the rotation script that's why it wasn't sending error. But i removed it and this what it says "Players.Player1.Backpack.LocalScript:8: attempt to index local 'mod' (a nil value)" , This is the error when i replaced the line 24 with rotateMod(_G.target:SetPrimaryPartCFrame(CFrame.new() * CFrame.Angles(0,math.rad(10),0)))

0
You should use SetPrimaryPartCFrame User#5423 17 — 7y

1 answer

Log in to vote
0
Answered by 7 years ago

Okay, What your doing is rotating every single part in the model, on its own axis. Roblox came up with this thing called,

SetPrimaryPartCFrame()

Wiki Link

You can use this by doing so;

Model:SetPrimaryPartCFrame(CFrame.new() * CFrame.Angles(0,0,0))

The only issue with this is, You need to set a primary part under the models property tab. When you set the primary part, remember that the whole model will orientate(rotate) around the center of this primary part. I usually create a brick, make sure its length's are the same, and set the center of it as the model.

0
what line i will set that in|?? npott13 23 — 7y
0
What ever line sets the CFrame of the part... Abstract_Life 65 — 7y
0
It doesn't work when i rotate it, the model disappear from the map npott13 23 — 7y
0
Are you using math.rad() if your rotating by degres Abstract_Life 65 — 7y
View all comments (5 more)
0
yes i am look at the script npott13 23 — 7y
0
Doesn';t work rotateMod(_G.target:SetPrimaryPartCFrame(CFrame.new() * CFrame.Angles(0,math.rad(10),0))) npott13 23 — 7y
0
@npott13 This is the answer, if not working on your script, you need to fix your script. Make sure your model has a PrimaryPart. superalp1111 662 — 7y
0
@superalp1111 it has primarypart, it rotates but just too far even i set the degree to 10 or 20 it rotates really wide like disappearing from the map. npott13 23 — 7y
0
This is the output, i am so stupid i forgot i had pcall function on the rotation script that's why it wasn't sending error. But i removed it and this what it says "Players.Player1.Backpack.LocalScript:8: attempt to index local 'mod' (a nil value)" , This is the error when i replaced the line 24 with rotateMod(_G.target:SetPrimaryPartCFrame(CFrame.new() * CFrame.Angles(0,math.rad(10),0))) npott13 23 — 7y
Ad

Answer this question