Inverse Kinematics for Tripod

So I am useing https://devforum.roblox.com/t/ez-fabrik-ik-v1-3-inverse-kinematics-intended-for-any-motor6d-rig/ for my tripod.
Now I have edited the script and my model for it to work. I have rigged up the Motor6D for the joints. I have tested but moving any of the “BigRTarget/BigLTarget/BigBTarget” wont move. The Motor6d will work though, I can edit them within properties and the move. I Should Note I am using Meshs.


--Get service
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RunService = game:GetService("RunService")

--Modules required
local IKControllerPointer = ReplicatedStorage.Source.LimbChain
local LimbChain = require(IKControllerPointer)

--Left leg chain motors
local tripod = workspace.Tripod

--Dont mess with root motor or else entire body will speeen
local lowerTorsoMotor = tripod.HumanoidRootPart

--Get the motors of the left leg chain
local lUpperLegMotor = tripod.Torso.LUpperLeg
local lLowerLegMotor = tripod.LLeg.LUpperLeg.LLowerLeg
local lfoot = tripod.LLeg.LLowerLeg.LFeet

--Get the motors of the right leg chain
local rUpperLegMotor = tripod.Torso.RUpperLeg
local rLowerLegMotor = tripod.RLeg.RUpperLeg.RLowerLeg
local rfoot = tripod.RLeg.RLowerLeg.RFeet

--Get the motors of the back leg chain
local bUpperLegMotor = tripod.Torso.BUpperLeg
local bLowerLegMotor = tripod.BLeg.BUpperLeg.BLowerLeg
local bfoot = tripod.BLeg.BLowerLeg.BFeet

--Create the left leg chain
local leftLegMotorTable = {lUpperLegMotor,lLowerLegMotor,lfoot}
local leftLegChain = LimbChain.new(leftLegMotorTable)

--create the right leg chain
local rightLegMotorTable = {rUpperLegMotor,rLowerLegMotor,rfoot}
local rightLegChain = LimbChain.new(rightLegMotorTable)

--Create the back leg chain
local backLegMotorTable = {bUpperLegMotor,bLowerLegMotor,bfoot}
local backLegChain = LimbChain.new(backLegMotorTable)


RunService.Heartbeat:Connect(function()
   
    local leftTarget = workspace.BigLTarget.Position
    local rightTarget = workspace.BigRTarget.Position
    local backTarget = workspace.BigBTarget.Postition

    leftLegChain:IterateOnce(leftTarget,0.1)
    leftLegChain:UpdateMotors()
	
	backLegChain:IterateOnce(backTarget,0.1)
	backLegChain:UpdateMotors()

    rightLegChain:IterateOnce(rightTarget,0.1)
    rightLegChain:UpdateMotors()

end)

Here is some photos inside the workspace.
image
image
image
image
image

2 Likes

Sorry but can you send a photo of the rig edit structure? Plus are there any errors in the output? Edit: I also see welds constraints are they perhaps interfering with the rig?

The Only Error is image
What Do you mean by Rig Edit Structure?
The weld Constraints are to hold the gray Collars around the leg.

Oh, that error means that you haven’t indexed the LUpperLeg properly. Looking at the hierarchy it’s within the Torso and the LLeg. Instead of indexing the Motor6D’s manually which I did initially, I recommend using a loop to get them and storing them in a dictionary assuming the Motor6D’s have been named uniquely

local tripod = workspace.Tripod

local modelMotor6Ds = {}

local modelDescendants = tripod:GetDescendants()
for _,descendant in pairs (modelDescendants) do
    if descendant:IsA("Motor6D") then
        modelMotor6Ds[descendant.Name] = descendant
    end
end
--now you can index the Motor 6d's by name through the dictionary obtained
local LUpperLegMotor = modelMotor6Ds["LUpperLeg"]

Also yeah make sure you rigged it properly. I’m currently using RigEdit which creates a joint structure like this:

1 Like

Ok So rerig the whole tripod with Rigedit. But Then It should work fine after that?

Well, it’ll need to be properly rigged where the Motor6D’s already had their C0 and C1 Positions set which RigEdit lite does for you. However, another way to know if it’s properly rigged is to insert an animation controller/humanoid in the model then attempt to manually animate it. If the joints rotate as it should then it’ll be good.

This is because in theory, my IK creates a vector from joint to joint:

If the joints are in the wrong position then issues will occur.

Oh Here is the Rig Structure

Well, it looks ok now make sure the motors are indexed properly or else the script will error and well the IK won’t have a chance to run at all.

1 Like

Sorry To Keep Bothering You. How do I index the motors. This is way Over My Head of understanding.

TripodTest.rbxl (496.4 KB)

Indexing is when you access data in the game which is what you were already doing previously using the . to access the Tripod model in the workspace

local tripod = workspace.Tripod

Now here is the automated version using a dictionary to find the Motor6D’s, try it out.

--Get service
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RunService = game:GetService("RunService")

--Modules required
local IKControllerPointer = ReplicatedStorage.Source.LimbChain
local LimbChain = require(IKControllerPointer)

--Left leg chain motors
local tripod = workspace.Tripod

local modelMotor6Ds = {}

local modelDescendants = tripod:GetDescendants()
for _,descendant in pairs (modelDescendants) do
    if descendant:IsA("Motor6D") then
        modelMotor6Ds[descendant.Name] = descendant
    end
end
--now you can index the Motor 6d's by name through the dictionary obtained
--Get the motors of the left leg chain
local lUpperLegMotor = modelMotor6Ds["LUpperLeg"]
local lLowerLegMotor = modelMotor6Ds["LLowerLeg"]
local lfoot = modelMotor6Ds["LFeet"]

--Get the motors of the right leg chain
local rUpperLegMotor = modelMotor6Ds["RUpperLeg"]
local rLowerLegMotor = modelMotor6Ds["RLowerLeg"]
local rfoot = modelMotor6Ds["RFeet"]

--Get the motors of the back leg chain
local bUpperLegMotor = modelMotor6Ds["BUpperLeg"]
local bLowerLegMotor = modelMotor6Ds["BLowerLeg"]
local bfoot = modelMotor6Ds["BFeet"]

--Create the left leg chain
local leftLegMotorTable = {lUpperLegMotor,lLowerLegMotor,lfoot}
local leftLegChain = LimbChain.new(leftLegMotorTable)

--create the right leg chain
local rightLegMotorTable = {rUpperLegMotor,rLowerLegMotor,rfoot}
local rightLegChain = LimbChain.new(rightLegMotorTable)

--Create the back leg chain
local backLegMotorTable = {bUpperLegMotor,bLowerLegMotor,bfoot}
local backLegChain = LimbChain.new(backLegMotorTable)


RunService.Heartbeat:Connect(function()
   
    local leftTarget = workspace.BigLTarget.Position
    local rightTarget = workspace.BigRTarget.Position
    local backTarget = workspace.BigBTarget.Position

    leftLegChain:IterateOnce(leftTarget,0.1)
    leftLegChain:UpdateMotors()
	
	backLegChain:IterateOnce(backTarget,0.1)
	backLegChain:UpdateMotors()

    rightLegChain:IterateOnce(rightTarget,0.1)
    rightLegChain:UpdateMotors()

end)
1 Like

There is an error in line two.
local IKControllerPointer = ReplicatedStorage.Source.LimbChain
Replicated Storage has been Underlined. line 45 RunService Is also Underline


Fixed the Problem for line 2
local IKControllerPointer = game.ReplicatedStorage.Source.LimbChain
fixed the run service. Now It counts
local RunService = game:GetService("RunService")
But Now local backTarget = workspace.BigBTarget.Postition wont work.

Maybe put a WaitForChild there? Usually, the error happens because it’s not loaded in yet.

1 Like

I dont’t think that will work for replicated storage for finding a limbchain script.

If You would Like Here is the RBXL TripodTest.rbxl (500.1 KB)

No idea, but I hotfixed the position of the vector joints, seems like my initial method didn’t work for really long legs. Now onto the current major issue, the model, yeah because the mesh parts are rotated it’ll act weird and this will mess with the CFrame math currently implemented. For reference every part in the basic R6 rig is orientated (0,0,0)


In contrast your legs are not (0,0,0) and they are rotated, consequently it’ll act weird.

However the solution for now would be create a basic part 0 and part 1 block that is orientated (0,0,0) then rig this part0 and part 1 to work with the IK method. I have had this problem before and currently I’m not too sure how to fix it, so I’m currently working on another IK method CCDIK.

Here is the rbxl file.

TripodTest.rbxl (497.9 KB)

1 Like

Thank you for you Help. I will try that And we will see what will happen.


Just To make sure This is what a Motor6d looks like


Work In progress all the legsJoints are 0,0,0
Now am I able to Weld The Mesh parts to The Leg Parts?

Also make sure the torso is (0,0,0) then you can start welding the mesh parts.

1 Like

Oof, Only The Right Leg Would Move.

Any Ideals How I could Fix this?