R6 IKPF (Inverse Kinematics Procedural Footplanting)

You could do a check if the player is jumping, and then apply your own animation if so.

1 Like

There’s a weird bug happening on the legs of my R6 Character.

So I was messing around in the script, doing configurations and stuff. After some time, I noticed that the leg of my character was moving weirdly. I tried to revert the changes in the script and it still happens. When I reinstalled it, the weird movement was still there. I checked every script in my game and it looks like it didn’t affect the movement at all. Then as a last attempt to detecting the problem, I installed it on a new experience and it was there.

I enabled the debug foot position and set the CFrame far away in which it doesn’t interfere and this is what I found. (red is raycast, black is the position of the feet)


Walking on the x-axis is perfectly fine

Walking in-between z & x-axis is slightly odd

Walking on the z-axis is odd (the feet doesn’t even lift off, it just slides)

I don’t know where this bug occurs but my guess is, it comes from the controller thing.

9 Likes

Oh wait actually I found it, nvm, thanks for the plug in tho :smiley:

3 Likes

https://gyazo.com/13bc8e47afcfaf89278b4b6e0f136332

https://gyazo.com/9e3c60d652d367aa6e84ffc0e52a3f2f – I like how the legs run when doing the dash-like move.

https://gyazo.com/3fa0d87f68929ac062458891c63e4c9a

Honestly, I really like it and thinking of implementing it.
It’s not the best but it’s good enough.

Great work! :+1:

4 Likes

I really like it but how would I remove or change the character from moving side to side?

1 Like

All the actual movement is done in the ProceduralAnimation class which creates the goal target for the inverse kinematics as @Vran_n is within the video.

Bounce CFrame makes it go up and down.
And the sway controls the rotation side to side, it’s been set to some arbitrary value try playing around with it or removing it entirely.
Modifying the WastCycle will mainly change the timing of when the bounce happens, such as it bounces up when the leg is being raised up.

function ProceduralAnimatorClass:MoveTorso(stepCycle,dt10,rootVelocity)
			local bounceCFrame = CFrame.new(0,self.WalkBounce*math.cos((self.WaistCycle+90+45)*2),0)

			local sway = math.rad(-relv1.X)+0.08*math.cos(self.WaistCycle+90)
			local swayY = 0.1*math.cos(self.WaistCycle)-2*math.rad(relv1.X)
			local swayX = math.rad(relv1.Z)*0.5*self.SwayX
			local goalCF = bounceCFrame*waist1*ANGLES(swayX,swayY,sway):inverse()

For @Vran_n sorry for the lack of reply, the legs being funky and not reaching the goal in a nice manner has to do with the inverse kinematics method, it’s iterative and doesn’t generate a 100% solution towards the goal it guesses and tries and doesn’t care if it looks weird or not TL;DR. This is known as an Analytical solution. This is also the reason why it is not compatible with Animations.

You could also reset the C0 of the limbs once in a while in order to make the CCDIK start from the baseline position and reset the rotations locking it in a “weird place”.

Where I learnt the IK method

These concavities are impossible to avoid in a heuristic IK algorithm (read: all of them except Analytic ). However, it is possible to “jump out of” concavities by adding large random offsets to each joint, and then attempting the IK solve again. This is known as “Simulated Annealing”. Implementing this is left as an exercise to the reader.

You can try replacing it with the classic 2 joint and 2 limb inverse kinematics as the code artifically creates an additional limb for R6 to make the R6 pretend it has a knee to raise “Up”.

the code for this is a one liner

function ProceduralAnimatorClass:MoveLegs(stepCycle,dt)
--Current IK method used
			Leg.CCDIKController:CCDIKIterateUntil(footPos,IKTolerance)
4 Likes

At this part of the script do I have to remove it entirely? If so does it breaks or not.

2 Likes

It’s the values set that control the swaying, For example try setting

			local sway = math.rad(-relv1.X)+0.08*math.cos(self.WaistCycle+90)

to

			local sway = 0

What do you notice?

I believe it should control the Z axis rotations which is the side to side movement.

3 Likes

It’s maybe because of WalkSpeed?

2 Likes

Put it in starter character scripts. So it will work properly!

2 Likes

very nice! thank you.
but there is a problem on direction.

2 Likes

no. you can see the problem even on faster speed and lower torso position.

3 Likes

i solved with just disabling little things. :smiley:

3 Likes

I tried using this on a scaled down character and…

Does anyone know how to fix this?

2 Likes

the legs seem to jerk in a specific direction, it might be because I disabled the torso rotations
but its really annoying

edit:
nope its not the torso thing, I re-enabled it and its still there, i do notice it happens specifically on sloped surfaces and ESPECIALLY on terrain

3 Likes

I love this tutorial and it really helped me for my game, but I do have a important question. How would I change the sound of the walking based on the material? I cannot seem the figure this out.

5 Likes

The foot step sound is a connection within the ProceduralAnimator class which returns the raycast result, so material detection should be possible there.

function ProceduralAnimatorClass:ConnectFootStepSound(sound : Sound)
	self.FootStep:Connect(function(raycastResult)
		local soundPositionAttachment = Instance.new("Attachment")
		soundPositionAttachment.WorldPosition = raycastResult.Position
		soundPositionAttachment.Parent = workspace.Terrain

		local footStepSound = sound:Clone()
		local randomPlaybackSpeed = self.RandomNumGenerator:NextNumber(0.7,1)
		footStepSound.PlaybackSpeed = randomPlaybackSpeed

		local reverbEffect = Instance.new("ReverbSoundEffect")
		reverbEffect.Density = 0.8
		reverbEffect.DecayTime = 1
		reverbEffect.Parent = footStepSound
		footStepSound.PlayOnRemove = true

		footStepSound.Parent = soundPositionAttachment
		soundPositionAttachment:Destroy()
	end)
end
2 Likes

I love this and it makes a roblox character look less like a toy but i do have one question how would i prevent this from happening (the original animation looks like this) or just how to simply disable this script while prone.

2 Likes

hey! I was messing around and changed the torso from moving side to side but up and down. How do I make it so the legs don’t move around a lot?

2 Likes

How can we make custom animations

2 Likes