Before we even get to the CFraming, I’m going to need sauce on this:
Have you done any benchmarking? With the preferable method I learnt now with os.clock()
Sample benchmarking code
local startTime = os.clock()
for i=1,10000 do
--Put your test code here
end
local deltaTime = os.clock() - startTime
print("Elapsed time method 1: " .. deltaTime)
Otherwise, yeah you got the formula correctly, but you haven’t applied ToObjectSpace correctly since you will need to inverse the parent CFrame, and instead you have inversed the goalCFrame instead so try this out I guess?
local goalCFrame = CFrame.new(chain.joints[i] + v/2, chain.joints[n]) -- The World CFrame of the current bone.
local offset = bones[i].Parent.CFrame:ToObjectSpace(goalCFrame) --> Should've turned the World CFrame into local orientation, but it's not quite exactly similar
bones[i].CFrame = offset
I’m not sure what the cause of the lag is. It could just be due to the constant resizing of the bone geometry which Roblox kinda sucks at judging from the resizing/changing geometry of base parts which I’m assuming should apply to this situation as well.
Otherwise, if you want to try a different algorithm I’m working on CCDIK which I gave out in this scripting support file: CCDIK rotation troubles - #2 by dthecoolest. Just if you are curious, but I believe FABRIK should already be light weight without constraints as-is from my experiences with using it for Motor6D’s which you can see in my project.