At first I thought to use toEulerAngles, but if you know anything about that method, it typically stinks. I also tried some tricks with toObjectSpace but I could never get it work perfectly. Would I use the CFrame’s components? toAxisAngle?
Assuming a and b are created using that method you’ve shown, you can assume the upVector of both CFrames points at least somewhat up.
There is a 90% chance I’m about to answer this wrong because the request is somewhat vague and there’s no explanation of what the application is for, but I’ll take a stab at it anyway.
--[[** Converts CFrame b such that it maintains its
upVector, but the lookVector points in approximately
the same direction as a.
@param a The CFrame which we are targeting.
@param b The CFrame which we are starting from.
@returns The rotated CFrame b.
**--]]
function rotateCFrameToMatch(a, b)
local upVector = b.upVector;
local rightVector = upVector:Cross(-a.lookVector);
local backVector = rightVector:Cross(upVector);
return CFrame.fromMatrix(b.p, rightVector, upVector, backVector);
end
Thank you for the reply.
I’ve taken a look at it, and I believe it will work although CFrame.fromMatrix appears to be nil?? Can’t find any pages on the wiki about fromMatrix either. Odd.
I’ve seen that constructor on intellisense, but yeah, not on the wiki. Was kinda hoping it actually exists, because it really takes out the annoying statement I just wrote.