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

A few questions about Model Parts and how to make a model rotate?

So I'm trying to make a model rotate, some people told be to add a PrimaryPart. Questions are;

  1. If a primary part is rotated will the rest rotate as well?
  2. If so then how would I rotate it?

Anyway if you want to see what I'm trying to do then visit the link below for a short vid/gif;

https://gyazo.com/4615d990de36978812a2d569dfe968db

currently this is part of my script;

while wait() do
				BodyPosition1.Position = characterT.CFrame:pointToWorldSpace(Vector3.new(-3,0,3))
				BodyPosition2.Position = characterT.CFrame:pointToWorldSpace(Vector3.new(3,0,3))
				BodyPosition3.Position = characterT.CFrame:pointToWorldSpace(Vector3.new(0,0,-3))
			end

and I'm trying to add a primary part;

local PP = Instance.new('Part') --Primary Part
			PP.Anchored = false
			PP.CanCollide = true
			PP.Position = characterT.Position
			PP.Transparency = 1
			PP.Name = 'PrimaryPart'

How would I make this rotate? Please answer my questions and help, and feedback is appreciated. Thanks for reading.

1 comment

0

It is recommended to use either TranslateBy or SetPrimaryPartCFrame if the current rotation of the model is important.

1 answer

✓ Accepted answer
  1. Only if you use SetPrimaryPartCFrame

  2. With SetPrimaryPartCFrame


There's no need for you to create the primary part with a script, and there's no need to name it "PrimaryPart" (although you can if you want). Just set it manually in studio. It's a property of the model.

SetPrimaryPartCFrame will change the CFrame of the primary part and move all other parts in the model relative to it. The function takes any CFrame value, just like normal.

To do rotation, we just use CFrame.Angles.

local mod = script.Parent

while wait() do
	local currentCF = mod.PrimaryPart.CFrame
	mod:SetPrimaryPartCFrame( currentCF * CFrame.Angles(0, math.rad(1), 0) )
end

We need to do currentCF * CFrame.Angles because of two reasons. First, we want the model to continue to rotate, not just snap to a rotation and stay there. Second, if we only specify a rotation, the position will be at 0, 0, 0, and we don't want that either.

You can also use mod:GetPrimaryPartCFrame() instead of simply mod.PrimaryPart.CFrame, not sure if there's a difference.

math.rad() converts degrees (0-360) into radians. Most people understand degrees way better, including me, so I use that.


Remember, the way this works is that everything will rotate around the primary part. So you may want to make sure your primary part is near the center of the model.

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