I am working on a game which allows some buildings to be placed and procedurally rotated.
I found the following rotation code which I am trying to incorporate:
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
Which is invoked as follows in my building placement script:
local center = model:GetModelCFrame()
TransformModel( model:GetChildren(), center, center * CFrame.Angles(0,math.rad(45),0), true )
The code works to some extent. The model does rotate, but it first jumps into the air and lands haphazardly before finally settling into the rotated position. However, the final rotation is far from an exact 45 degrees due to the physics effect of jumping and settling back down.
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.
Thanks, Andy