IK Module with skinned mesh bones?

I have been trying to apply an IK module to a skinned mesh I have made and the only IK modules I have found are ones that use Motor6Ds which have very different properties to bones.

I eventually found one that doesn’t use Motor6Ds, specifically this one.

I modified the module a bit to make it work with my skinned mesh but when ever I run it I get this:

Here is the modified part of the module:

for i = #self.Positions, 1, -1 do
			--self.Motors[i].WorldPosition = self.Positions[i]

			if i ~= 3 then
				--local dir = Vector3.new(b.x-self.Positions[i].x, b.x-self.Positions[i].y, b.z-self.Positions[i].z).Unit

				--local position = basePos + Vector3.new(x*dir.X,y,x*dir.Y)

				--part.CFrame = CFrame.new(position,b)
				
				
				--print(CFrame.lookAt(self.Positions[i], self.Positions[i+1]))
				self.Motors[i].WorldPosition = self.Positions[i]
				--print(self.Positions[i+1])
				var = CFrame.lookAt(self.Positions[i], self.Positions[i+1])
				print(var)
				--self.Motors[i].WorldOrientation = Vector3.new(var.LookVector, var.UpVector, var.RightVector)
				self.Motors[i].WorldOrientation = var.LookVector*180
			else
				self.Motors[i].WorldCFrame = CFrame.new(self.Positions[i])
			end
			
		end

for i = #self.Positions, 1, -1 do The length of self.Positions is 3 as the table contains the positions of the three bones. self.Motors contains the actual bones.

The problem of this I believe is the CFrame.lookAt as for some reason when I set the WorldOrientation of the bone it does what is shown in the image but I am not sure how I would fix it.

Any help would be appreciated.

3 Likes