I’ve started work on a module which allows the construction and manipulation of objects with an arbitrary number of joints and an end effector. Though it’s still by all means a work in progress, I’ve managed to create a function which automates the process of moving a target towards an end effector. In publishing it here, I intend to expose it so that you guys can give feedback as to what I can fix, and what I can add to this library.
The neat thing about this is that the only thing that the front-end user needs to do is specify the weld CFrames, with the option of setting constraints on ranges of motion. Thus, if you have a rudimentary understanding of welds, then you can most certainly use this module. You can see it in action at this link: http://www.roblox.com/Jointed-automatic-robot-arm-WIP-place?id=178795382
It seems quite advanced, but aside from the module itself, the code needed to carry that out was rather minimal:
[code]local Robotics = require(game.ServerScriptService.Robotics);
– making the arm
local bin = script.Parent;
local eff = bin.effector;
local w0 = Robotics.MakeWeld(bin.Base, bin.Joint0, );
local w1 = Robotics.MakeWeld(bin.Arm2, eff, );
local joint0 = Robotics.MakeBallJoint(bin.Joint0, bin.Arm0, <weld/joint arguments>);
local joint1 = Robotics.MakeHingeJoint(bin.Arm0, bin.Arm1, <weld/joint arguments>);
local joint2 = Robotics.MakePivotJoint(bin.Arm1, bin.Arm2, <weld/joint arguments>);
local MachineArm = Robotics.MakeChain(eff, joint0, joint1, joint2);[/code]
Now, in order to move my end effector to a given position, I need only a simple loop, along with a few extra lines of code:
while (eff.Position-target).magnitude>1 and running do
local e = eff.Position;
local delta = target-e;
local dt = wait();
local de = delta.unit*dt*10;
local params, t = MachineArm.GuessParamOffset(de);
local args0, args1, args2 = params[1], params[2], params[3];
MachineArm.joints[1].ShiftSwing(args0[1], args0[3]);
MachineArm.joints[1].ShiftTwist(args0[2]);
MachineArm.joints[2].ShiftFlex(args1[1]);
MachineArm.joints[3].ShiftFlex(args2[1]);
MachineArm.joints[3].ShiftTurn(args2[2])
MachineArm.Update();
end
The result:
External Media
The mathematics behind this are a bit involved, but fortunately most of the really hard stuff is taken care of by the module. The current API is somewhat limited, but I plan to add many more interesting features in the future, including pre-programmed routines and additional joint types. As of now, the module supports hinge, pivot, and ball joints.
To assemble an object with multiple joints, you need only create the joints and weld an effector to the last one, then call Robotics.MakeChain(effector, joint1, joint2, …). Any number of joints may be specified.
I’ve put in a decent amount of documentation on the features of this library, along with how to use them, inside the script. It also uses my matrix math module, so you’ll need to put that in your game also. Both can be found at these two links: