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

How do you rotate a model?

There is a Model:MoveTo and Model:TranslateBy, but no Model:RotateBy. I have a 'master' model I need to re-spawn in various locations within a map and facing various directions. I can use MoveTo to position the model, but how do I rotate it? I've been thinking of having it spawn on a rotating platform, but that seems overly complicated.

1 answer

Note, this is not my work, it's something I have been using that is free-source for a while:


--[==[
		:RotateModel:

	Rotates a model around a center point.

>>	How to use

		RotateModel(model, center, axes [, inc [, step]])

			model	:	Object	:	the model to rotate
			center	:	CFrame	:	the center
			axes	:	table	:	a table of which axes to rotate on and how much to rotate them by (in radians)
			inc		:	number	:	how many times to apply the rotation (optional)
			step		:	number	:	how long to wait between each application (optional)

]==]

function _G.RotateModel(model,center,axes,inc,step)
	local origin = {}
	for _,child in pairs(model:GetChildren()) do
		if child:IsA"BasePart" then
			origin[child] = center:toObjectSpace(child.CFrame)
		end
	end
	for i = 1,inc or 1 do
		center = center  * CFrame.fromEulerAnglesXYZ(unpack(axes))
		for part,cf in pairs(origin) do
			part.CFrame = center:toWorldSpace(cf)
		end
		if step then wait(step) end
	end
end

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