Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do I align CFrame properly?

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

2 comments

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.

0

Why don't you model the whole thing together and make the center sphere the new Primary Part and just rotate that?

1 answer

✓ Accepted answer

#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:


Hope it helps!

1 comment

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.

This discussion is preserved as it was. New answers, comments, and votes are closed.