How to inverse kinematic a snake model

im trying to make a snake animation, also I just found out about inverse kinematic and I think that fits better for the animation so when the player turns the whole character wont be turn all at once, I dont know anything about inverse kinematic at the moment and all the tutorial about it in the internet are not the one that I needed
image
I have this model with 9 parts and a humanoid root part in the head, I want the body of the snake follow the humanoid root part like this (I want the gun to be the humanoid root part also vid not mine)

workspace

(connectors are the smalle parts)
image
(while the body are the large parts)
image
(1 is closest to the head and 4/3 is the furthest away, the tail is the last part)
image

if you have any idea how to do this please help me ty

1 Like

That doesn’t look like inverse kinematics to me. Inverse kinematics is a way to make a limb move to a specified position relative to the body. That looks almost more like basic constraints, possibly Verlet integration. To get started, I’d move the first link, or the head of the snake. Then take the second link and move it towards the first link by the distance required to meet the first link. Then take the third and move it towards the second by the distance required to just touch the second link.
You can factor in rotation with all of this using CFrames pretty easily.
The biggest downside to this approach is that your snake will be unaffected by anything bumping into the links, but all the links in the video are anchored and I think this is pretty close to what they’re doing. If you really wanted the extra interaction with unanchored snakes, I would use Verlet integration with some custom application of forces to move the snake.

2 Likes

is there any post or article about it?, also do you have any idea about it because this seems like a higher level

As i can tell, this seems to have gone unnoticed. Here is a free place that someone created with the same inverse that the video uses. (i assume you found this post) How to make a snake like movement, I have edited the model in a way so you dont need connectors and you can slightly mash it together for better results.

  • Module to put into game.ReplicatedStorage
local IKFramwork = {}

function IKFramwork.SolveIK(segments, startPart, endPart)
	local prevSegment = nil;
	for i = #segments, 1, -1 do
		local goalPosition;
		local currentSegment = segments[i];
		
		-- Set the goalPosition as the endPart if there was not a previous iteration
		if (not prevSegment) then
			goalPosition = endPart.Position
		else
			goalPosition = (prevSegment.CFrame * CFrame.new(0,0,prevSegment.Size.Z/2.2)).p
		end
		
		local startPositionOfThisSegment = (currentSegment.CFrame * CFrame.new(0,0,currentSegment.Size.Z/2.2)).p
		
		-- Set the CFrame from the goalPosition, facing the segment's current start position
		currentSegment.CFrame = (CFrame.new(goalPosition, startPositionOfThisSegment) * CFrame.new(0,0,-currentSegment.Size.Z/2.2)) * CFrame.Angles(0,math.pi,0)
		
		prevSegment = currentSegment
	end
end

return IKFramwork

  • Script to put into your snake model
local rightArmPrimary, gunGrip = game.Workspace["S-SpawnArea"] --[[Here clone the head into workspace and name it S-SpawnArea.]], script.Parent.Head.Head --[[Change this to your snakes head instance.]]


local RS = game:GetService("RunService")
local Framework = require(game.ReplicatedStorage.IKFramwork)

local rightArmSegments = {script.Parent.seg7.main,script.Parent.seg6,script.Parent.seg5,script.Parent.seg4,script.Parent.seg3,script.Parent.seg2,script.Parent.seg1} --[[Change segments here to your snakes segments (no connectors needed, just union your connectors together.), If your snake is backwards while implementing this part, reverse the instances in the table 

(Example:

local rightArmSegments = {script.Parent.seg7,script.Parent.seg6,script.Parent.seg5,script.Parent.seg4,script.Parent.seg3,script.Parent.seg2,script.Parent.seg1} 

converts to:

local rightArmSegments = {script.Parent.seg1,script.Parent.seg2,script.Parent.seg3,script.Parent.seg4,script.Parent.seg5,script.Parent.seg6,script.Parent.seg7}
)]]

RS.Heartbeat:Connect(function()
	Framework.SolveIK(rightArmSegments, rightArmPrimary, gunGrip)
	--Framework.SolveIK(leftArmSegments, leftArmPrimary, gunHandle)
end)

I hope i explained this well enough for you to bring your beautiful snake model to life,
And also for learning experience, The framework uses a simple CFrame calibrator to change CFrames relative to heads current movement. (You moving the head to change the snakes position orientations, like the video you have attached in the original post.), SHOULD result in this:
robloxapp-20220626-1233138.wmv (762.8 KB)

  • Regards, TrapzFX.
1 Like

(P.S. You should now have the ability to move your snake’s body by moving the head!)

1 Like

how do iI make it work when the player move??, I want it to be controlled by the player and it just move the head and not the whole body lol
image

For that i do not know. I think you may have used inverse incorrectly here. Maybe search a few tutorials?
I cannot help you here as i currently am busy with SITE-ANDROMEDA

2 Likes