I have managed to make inverse kinematics for 2 joints, but I also want to make inverse kinematics
for 3 joints, with the purpose of mainly procedurally animating robots.
The problem I am facing is that any tutorials I find fail to explain what everything does which makes it hard if not impossible for me to implement.
Basically what I would like to achieve would look something like this:
The neon ball is the origin of the leg, and the foot is the target.
Any help such as directions to useful resources or already made Geometric-based 3 joint inverse kinematics that I could learn from will be appreciated!
Otherwise I can suggest my CCD and my module on it but it is an iterative method which doesnt always generate the same end result depending on the initial conditions.
While this does in fact work like the example above that I wanted to achieve stuff likes mechs that you had in your posts wont work with this, as this mainly only works for stuff like spiders. and other insects
and another note, once you get the angle in radiants you still have to substract the angle from math.pi (or 180 degrees in radiants)
function IKSolver.Solve3Joint(originCF: CFrame, targetPos: Vector3, l1: number, l2: number, l3: number): (CFrame, number, number)
local localized = originCF:PointToObjectSpace(targetPos)
local l4 = localized.Magnitude
local planeCF = originCF * CFrame.fromAxisAngle(
(Vector3.zAxis * -1):Cross(localized.Unit), -- Axis
math.acos(-localized.Unit.Z) -- Angle
)
local ed = l4 - l2
local a4 = math.acos((ed^2 + l3^2 - l1^2)/(2*ed*l3))
local a1 = math.acos((l1^2 + ed^2 - l3^2)/(2*l1*ed))
local a2 = math.pi - a1
local a3 = math.pi - a4
a1 = math.pi - a1
a2 = math.pi - a2
a3 = math.pi - a3
return planeCF * CFrame.Angles(math.rad(-90),0,0), a1, a2, a3
end
here would be the entire code for the arm (I removed some other stuff such as a part of code that makes sure that the hand fully reaches the target instead of pointing at it)