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

How to smoothly rotate a model with 12 parts in?

Asked by
Nidoxs 190
9 years ago

I have 12 parts in a model how do I rotate the whole model (From ( 0,0,-30) to (0,0,-60)) This does one part at a time. How do I do the whole model at once? I don't need a very good graphics card do I like people are saying? (That was 109 parts. This is 12 it should work with no lag right?)

local Model = script.Parent


function Move()
    for Index,Part in pairs(Model:GetChildren()) do
        if Part:IsA("BasePart") then
                     for i=1,30 do 
    Part.CFrame = Part.CFrame*CFrame.fromEulerAnglesXYZ(0,0,-.1) 
wait(.1)    
    end  
wait()
end
end 
end 


script.Parent.Handle.ClickDetector.MouseClick:connect(Move)

1 answer

Log in to vote
1
Answered by
noliCAIKS 210 Moderation Voter
9 years ago

The issue is not in your graphics card, but in the program flow. As you currently have it, with the loop through the parts outside, and the loop from i=1,30 inside, it will loop through each part and rotate them one by one, waiting until the previous rotation is finished because wait(.1) is inside the for i=1,30 do loop.

To fix it, switch the for loops, so that 30 times, it rotates all parts slighly and waits for a bit, rather than for all parts rotate the part 30 times while waiting before going to the next part.

local Model = script.Parent

function Move()
    for i=1,30 do
        for Index,Part in pairs(Model:GetChildren()) do
            if Part:IsA("BasePart") then
                Part.CFrame = Part.CFrame*CFrame.fromEulerAnglesXYZ(0,0,-.1)
            end
        end
        wait(.1)
    end
end

script.Parent.Handle.ClickDetector.MouseClick:connect(Move)
0
So you just had to change some of their positions? woodengop 1134 — 9y
0
@ TheContinentofEurope What do you mean? By positions, are you referring to the program flow, or the positions of the parts? noliCAIKS 210 — 9y
0
Program. sry :P woodengop 1134 — 9y
0
@ TheContinentofEurope Well, yes, but it makes a huge difference. It's like doing `error() object:Destroy()` instead of `object:Destroy() error()`. Similarly to error(), wait(.1) influences the way the rest of the program is executed, so the order of operations matters a lot. noliCAIKS 210 — 9y
View all comments (5 more)
0
Although this solution works completely fine (and its good), using PrimaryPartCFraming would make the code a lot shorter and much more effecient. DigitalVeer 1473 — 9y
0
@DigitalVeer Maybe that was what the asker intended, but wouldn't that do something completely different? This script rotates the parts independently from eachother, while SetPrimaryPartCFrame would rotate the *positions* around the primary part too, instead of just rotating everything around it's own axis. It depends on what the asker wants. noliCAIKS 210 — 9y
0
I only assumed due to in the question, he wrote "how do I rotate the whole model" DigitalVeer 1473 — 9y
0
@DigitalVeer I understand. It may be useful if you post your answer as well, in case that's waht the asker intended. (Not in reply to you, but on a side note, I noticed an mistake in my answer and fixed it.) noliCAIKS 210 — 9y
0
It didn't quite work as I wanted it to. But it is fine. I have scraped the idea I was doing. Thanks! Nidoxs 190 — 9y
Ad

Answer this question