title: Roblox - Rotating a Model
body: <p>I am working on a game which allows some buildings to be placed and
  procedurally rotated.</p>
  
  <p>I found the following rotation code which I am trying to incorporate:</p>
  
  <pre><code>function TransformModel(objects, center, new, recurse)
      for _,object in pairs(objects) do
          if object:IsA("BasePart") then
              object.CFrame =     new:toWorldSpace(center:toObjectSpace(object.CFrame))
          end
          if recurse then
              TransformModel(object:GetChildren(), center, new, true)
          end
      end
  end
  </code></pre>
  
  <p>which is invoked as follows in my building placement script:</p>
  
  <pre><code>local center = model:GetModelCFrame()
  TransformModel( model:GetChildren(), center, center * CFrame.Angles(0,math.rad(45),0), true )
  </code></pre>
  
  <p>So the code works, somewhat... The model does sort of rotate but only after it jumps into the air and lands haphazardly before finally settling down in the rotated position, although its far from an exact 45 degree rotation after the physics effect of jumping in the air and settling back down.</p>
  
  <p>I am not quite sure but I suspect there is a better way to accomplish this where the model smoothly rotates. Any help would be greatly appreciated.</p>
  
  <p>Thanks,
  Andy</p>