Hi, in this tutorial by EggMoose, he uses the value of C1 to translate the gun so it aligns
with the camera.
if you scroll through, to the declaration of the function below
local function aimDownSights(aiming)
local start = joint.C1;
local goal = aiming and joint.C0 * offset or CFrame.new();
aimCount = aimCount + 1;
local current = aimCount;
for t = 0, 101, 10 do
if (current ~= aimCount) then break; end
game:GetService("RunService").RenderStepped:Wait();
joint.C1 = start:Lerp(goal, t/100);
end
end
What I don’t understand; how is the goal CFrame for C1 computed; what’s the thinking behind it? I’ve been analyzing the code for about a week or so now, and still don’t understand.
This is essentially algebraic reorganization notice how this is the same as the previous line except that both sides are being multiplied by the inverse of joint.Part1.CFrame. Because CFrames are matricies joint.Part1.CFrame cancels out with joint.Part1.CFrame:Inverse() to give the identity matrix. Simply, this would be n * (1/n) = 1 if we were not dealing with matrices.
– recall though that joint.Part0.CFrame == camera.CFrame thus:
Also recall from what he mentioned previously:
and we’re setting joint.Part1.CFrame = camera.CFrame
Assuming that both statements are true from what he said you can do a substitution, for joint.Part1.CFrame:inverse() as camera.CFrame:inverse() and joint.Part0.CFrame as camera.CFrame
and now what we know from my previous statements, these two should cancel and allow us to say:
joint.C1 = joint.C0
This is all assuming that both statements about joint.Part0.CFrame is camera.CFrame and that joint.Part1.CFrame is set to camera.CFrame. If that fact is not true the substitution as I’m reading it does not work and these terms do not cancel.
Hope that helps, if I royally misunderstood feel free to let me know.