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

How do you rotate a model?

Asked by 10 years ago

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

Log in to vote
1
Answered by
Sublimus 992 Moderation Voter
10 years ago

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
Ad

Answer this question