The issue:
I am using this script to have a tool gun be able to aim when holding right mouse button, without using a viewmodel.
As You can see in the video, it works, but there are 2 main problems. The hand is positioned weirdly on the gun, and the lowerarm and upperarm don’t follow the hand (I thought they would since there is a motor6D joint between them).
I am very new to scripting CFrames, especially messing with confusing to me C0 and C1 values, so if someone could help me I would greatly appreciate it!
tool.Equipped:Connect(function()
equipped = true
joint = Instance.new("Motor6D");
joint.C0 = CFrame.new(0.5, -0.3, -2);
joint.Part0 = head;
joint.Part1 = tool.Handle;
joint.Parent = char.Head;
end)
tool.Unequipped:Connect(function()
equipped = false
end)
repeat task.wait() until equipped == true
local aimCount = 0;
local offset = tool.Handle.CFrame:inverse() * tool.Aim.CFrame;
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
local function onInputBegan(input, process)
if (process) then return; end
if (input.UserInputType == Enum.UserInputType.MouseButton2) then
aimDownSights(true);
end
end
local function onInputEnded(input, process)
if (process) then return; end
if (input.UserInputType == Enum.UserInputType.MouseButton2) then
aimDownSights(false);
end
end
game:GetService("UserInputService").InputBegan:Connect(onInputBegan);
game:GetService("UserInputService").InputEnded:Connect(onInputEnded);