This is part of EgoMoose’s inverse kinematics code.
(FABRIK (Inverse kinematics) - YouTube)
The .rbxl on the link has the code that I asked.(It is the same as the rbxl based on this question.)
function chain:backward()
-- backward reaching; set end effector as target
self.joints[self.n] = self.target;
--self.n is #joints
for i = self.n - 1, 1, -1 do
local r = (self.joints[i+1] - self.joints[i]);
local l = self.lengths[i] / r.magnitude;
-- find new joint position
local pos = (1 - l) * self.joints[i+1] + l * self.joints[i];
self.joints[i] = pos;
end;
end;
I can’t understand ( local r / local l / local pos ). I just know how it works without understanding.
I expected there would be a code for directions(.unit), but I don’t think there is.
I’m a bit confused. Can you explain?
joints
[1] = -3, 7.5, -10,
[2] = -2.66484642, 11.2537212, -11.3406143,
[3] = -2.32969284, 15.0074425, -12.6812286,
[4] = -1.99453926, 18.7611637, -14.021843,
[5] = -1.65938568, 22.5148849, -15.3624573,
[6] = -1.3242321, 26.2686062, -16.7030716
lengths
[1] = 3.999999761581421,
[2] = 3.999999761581421,
[3] = 3.999999761581421,
[4] = 3.999999761581421,
[5] = 3.999999761581421