So I’m actually pretty familiar with trigonometry and geometry. So tan cos and sin have different formulas for each. You have to figure out your sides for example opposite, adjacent and hypotenuse.
Then as they stated you plug your numbers in based off of the chart above. Using the Pythagorean Theorem.
Now you use the following a,b and c as a unknown value that now has a specific purpose. To help you plug them into the equation. I’d use mathway or some form of geometry/trigonometry calculator.
Then once done insert all your info into the code they’ve provided.
-- OriginCF is the CFrame of the shoulder, direction is important
-- TargetPos is the Vector3 position we're reaching to
-- l1 and l2 are both numbers that represent the length of the segments of the arm
local function solveIK(originCF, targetPos, l1, l2)
-- put our position into local space in regards to the originCF
local localized = originCF:pointToObjectSpace(targetPos)
-- this breaks if OriginCF and targetPos are at the same position
local localizedUnit = localized.unit
-- the distance to from originCF.p to targetPos
local l3 = localized.magnitude
-- build an axis of rotation for rolling the arm
-- forwardV3 is Vector3.new(0, 0, -1)
local axis = forwardV3:Cross(localizedUnit)
-- find the angle to rotate our plane at
local angle = acos(-localizedUnit.Z)
-- create a rotated plane to base the angles off of
local planeCF = originCF * fromAxisAngle(axis, angle)
-- L3 is between the length of l1 and l2
-- return an offset plane so that one part reaches the goal and "folded" angles
if l3 < max(l2, l1) - min(l2, l1) then
return planeCF * cfNew(0, 0, max(l2, l1) - min(l2, l1) - l3), -pi/2, pi
-- l3 is greater than both arm lengths
-- return an offset plane so the arm reaches its goal and flat angles
elseif l3 > l1 + l2 then
return planeCF * cfNew(0, 0, l1 + l2 - l3), pi/2, 0
-- the lengths check out, do the law of cosines math and offset the plane to reach the targetPos
-- return the offset plane, and the 2 angles for our "arm"
else
local a1 = -acos((-(l2 * l2) + (l1 * l1) + (l3 * l3)) / (2 * l1 * l3))
local a2 = acos(((l2 * l2) - (l1 * l1) + (l3 * l3)) / (2 * l2 * l3))
return planeCF, a1 + pi/2, a2 - a1
end
end
-- simple demo for how its called
local TARGET_POS = Vector3.new(0, 3, 0)
local SHOULDER_C0_VALUE = CFrame.new(1, 0.4, 0)
while wait() do
local shoulderCF = upperTorso.CFrame * SHOULDER_C0_VALUE
local plane, shoulderAngle, elbowAngle = solveIK(shoulderCF, TARGET_POS, 0.515, 1.1031)
shoulderMotor.C0 = upperTorso.CFrame:toObjectSpace(plane) * cfAngles(shoulderAngle, 0, 0)
elbowMotor.C0 = lowerC0 * cfAngles(elbowAngle, 0, 0)
-- keep the C1 values consitent, they shouldn't need to be set every frame
end
Over all if you’re struggling with how to solve or set it up I’d use a outside website like Khan Academy or some sort of video/lesson to learn how to do it.