How do you rotate an object about an axis that it is not lined up with?
Here’s an example:
Lets take this cube. Its axes are represented by the red, green and blue lines. I want to rotate the cube about the yellow line! this is an easy task as the red axis happens to be lined up with the yellow line.
If I wanted to do this via code, all I would have to do is add a few degrees to the X argument of the part’s orientation:
.
.
.
But what if the part is already rotated a certain way? I want all of those rotations to remain the same, but I still want to rotate it around the yellow line like so:
.
.
.
None of the axes line up with the yellow line however. When i try to rotate it with any of the three axes, it will not rotate around the yellow line.
What i need is a collection of changes for each axis that will produce the desired rotation:
Nevermind. I misunderstood what CFrame.fromAxisAngle() does, this ended up being exactly what I was looking for. Thank you.
For anyone who happens upon this thread, this piece of code achieved what I needed:
local function update(deg)
--convert to radians
deg = math.rad(deg)
--Direction of the modified rotation
local rotCF = CFrame.fromAxisAngle( Vector3.xAxis, deg) --+ Motor.C0.Position
--Update Motor
Motor.C0 = rotCF * OriginalCF
end
There’s a model set up with a motor6d connected to a rotated part. This function accepts an angle given in degrees, and rotates that model along the designated axis.