The model has some parts that are within other parts (CFramed into eachother). I'm not sure if that matters, but the question remains the same. How can I rotate a model through scripting?
Rotate about what? Rotation is an operation around a particular point. We can use GetModelCFrame as the default, but you could substitute whatever CFrame you wanted.
Secondly, in what way are you rotating it? Rotating around a single axis will work exactly how you'd expect, so that would be the easiest thing.
There's a few ways to accomplish the math, but here's the way that I like to think about it, because it makes the most sense in my head:
function rotate(cframe,about,x,y,z) local within = about:toObjectSpace(cframe); local out = about * CFrame.Angles(x,y,z); return out:toWorldSpace(within); end
We would then use rotate
on each part's CFrame in the model that we want to rotate about about
(which could be the model's CFrame gotten through GetModelCFrame
, or any other point, if you have one in particular you want). If we wanted to spin it 90 degrees around the vertical axis, we could give x,y,z
the parameters 0,math.pi/2,0
.