Sorry about that, here:
local MAXIMUM_DISTANCE = 20;
local raycastParams = RaycastParams.new();
raycastParams.FilterDescendantsInstances = {script.Parent};
raycastParams.FilterType = Enum.RaycastFilterType.Exclude;
local calculateAngle = function(targetHeight : number, size : number): (number, number)
local secondAngle = math.acos((size^2*2-(targetHeight^2))/(2*(size^2)));
if (secondAngle ~= secondAngle) then error("Woah dude, I can't reach that far... I have small arms y'know?") end;
local firstAngle = (math.pi - secondAngle)/2;
return firstAngle, secondAngle;
end
local updatePantograph = function(Pantograph)
local RaycastResult = workspace:Raycast(Pantograph.OriginRay.Position, Pantograph.OriginRay.CFrame.UpVector * MAXIMUM_DISTANCE, raycastParams)
if RaycastResult then
local Wire = RaycastResult.Instance
local Distance = RaycastResult.Distance - Pantograph.VisualHand.Size.Y/2;
local lowerArm = Pantograph.LowerArm;
local upperArm = Pantograph.UpperArm;
local lowerSize = (lowerArm.A.Position - upperArm.A.Position).Magnitude;
local upperSize = (upperArm.A.Position - Pantograph.VisualHand.A.Position).Magnitude;
local firstAngle, secondAngle = calculateAngle(Distance, (lowerSize + upperSize)/2);
lowerArm.Motor.C0 = CFrame.Angles(0,0,math.pi);
lowerArm.Motor.C1 = CFrame.Angles(0,-math.pi,firstAngle + (math.pi * 0.5));
upperArm.Motor.C1 = CFrame.Angles(0,0,-secondAngle);
local handAngle = (upperArm.Orientation - Wire.Orientation).X; --Added your code here
Pantograph.VisualHand.Motor.C1 = CFrame.fromOrientation(math.rad(-handAngle) + math.pi, 0, 0);
end
end
game:GetService("RunService").Heartbeat:Connect(function()
updatePantograph(script.Parent.Panto);
end);