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

How do I align CFrame properly?

Asked by 8 years ago

Hi, I'm fairly new to PrimaryParts and the usage of them, or physics in general when it comes to scripting. I wanted to try out a wind turbine but I had become so confused, as each wing of the turbine would spin in circles instead of along the base point of the turbine.

The gyazo is here: gyazo

My code was this:

local pp = script.Parent
pp.Rotate1.PrimaryPart = pp.Rotate1.MeshPart
pp.Rotate2.PrimaryPart = pp.Rotate2.MeshPart
pp.Rotate3.PrimaryPart = pp.Rotate3.MeshPart
a = 0
while wait() do
pp.Rotate1.PrimaryPart.CFrame = pp.Rotate1.PrimaryPart.CFrame * CFrame.Angles(0, 0.005, 0)
pp.Rotate2.PrimaryPart.CFrame = pp.Rotate2.PrimaryPart.CFrame * CFrame.Angles(0, 0.005, 0)
pp.Rotate3.PrimaryPart.CFrame = pp.Rotate3.PrimaryPart.CFrame * CFrame.Angles(0, 0.005, 0)

wait()
a = a+3 
end

and the hierarchy was this: here

0
Your code is going to simply rotate each blade around their center, rather than around another point. The math for that is a good bit more complicated. GoldenPhysics 474 — 8y
0
Why don't you model the whole thing together and make the center sphere the new Primary Part and just rotate that? EzraNehemiah_TF2 3552 — 8y

1 answer

Log in to vote
1
Answered by 8 years ago

What you can do

Instead of doing all the math, why not rotate the entire model together?


SetPrimaryPartCFrame

This function of Models named SetPrimaryPartCFrame() can change the CFrame of a primary part and all of the other parts in the model according to that original movement, so all the parts move together in unison.

script.Parent:SetPrimaryPartCFrame(script.Parent.PrimaryPart.CFrame*CFrame.Angles(0,math.pi,0))

Final Product

You should probably tab or indent in your code to make it easier to read!

local pp = script.Parent

a = 0
while wait() do
    pp:SetPrimaryPartCFrame(pp.PrimaryPart.CFrame * CFrame.Angles(0, 0.005, 0))
    wait()
    a = a+3 
end

Click here to see what it looks like in game: * Gif 1 * Gif 2


Hope it helps!

0
Awesome work! Thank you very much. I've always had a habit of doing this crazy math, I knew there was a shortcut, just needed that one person to find it for me. good_evening 7 — 8y
Ad

Answer this question