[SOLVED] Problem with pantograph

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);

Thanks!

With the rotation fixed its still a little bit too high how would I fix this?

image

Also a question, this model isn’t the final model so when it comes time for me to re rig it what should the code be if all motors C0 and C1 and A and B parts orientations and positions are all at 0, 0, 0? So basically like the first model I gave you

  1. You can just subtract the distance variable by a set amount, for example, the width of that rope. So like - 0.1 or so.

  2. Assuming the model is similar you just need to do the same you did up to this point. Then just copy over the C0 and C1 values from the model I gave you. It should work the same.

Ok I’ll give that ago.

Changing C0 and C1 properties of motors and welds isn’t exactly easy… it always messes up the part and stuff, keeping the default values are just easier

I’ve managed to fix these.

Issue 1 was fixed and issue 2 was solved after changing some of the values around.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.