CFrame Legs Procedural Movement R6

Hello, I want to make the legs of the player look where he is moving like the game Write a letter or even evade. i tried to do this and it work but it’s a bit messed up if anyone with a big brain can help me it will be very nice ! example: Test - YouTube

local LeftLeg = script.Parent:WaitForChild('Torso'):WaitForChild('Left Hip')
local RightLeg = script.Parent:WaitForChild('Torso'):WaitForChild('Right Hip')
local CenterOfLegs = Vector3.new(0,-1,0)
local character = script.Parent
local cam = workspace.CurrentCamera
local humanoid = character:WaitForChild("Humanoid")

while wait(0.001) do
    movementDirection = cam.CFrame:vectorToObjectSpace(humanoid.MoveDirection).Unit

    
    LeftLeg.C0 = CFrame.new(CenterOfLegs) * CFrame.new(movementDirection)--messed up part
    RightLeg.C0 = CFrame.new(CenterOfLegs) * CFrame.new(movementDirection)--messed up part
    
end
2 Likes

seems like you would want to use animations for this, and create different animations for the 8 directions that they walk in in the example video.

then you can detect which direction they are walking with something like Humanoid.MoveDirection or just use user input service

4 Likes

Furthermore, you could also adjust the weights between the animations to be able to accurately hit all degrees of movement

3 Likes

i already have a script that use 8 animations for the strafing. but it’s not as smooth as the CFrame. the video is a bit laggy im sorry but you can try the game here Write a Letter 🎙️ VC - Roblox you will see they use Cframe.( well i think they do)

1 Like

wait you mean that with only 8 animations that can be as smooth as CFrame ?

1 Like

Ive never tried it myself, but it stands to reason that it should be doable.

Lets take for example: You have an animation for each of these directions - represented by the arrows - in this illustration. You play one animation when walking forward, and one animation when walking left

image

You could also theoretically get the animation for the 45 degree direction (blue arrow) by playing each of the two animations at 50% weight rather than just playing one or the other

image

1 Like

I’m not very well versed in the mathematics behind inverse kinematics, but maybe this open source resource has code that could help you.

I’ll also say procedural will yield a nicer looking result as opposed to using flat, static animations.

1 Like

If you don’t want to use animations…

You may want to look into inverse kinematics

Here are some resources:

Of course there are other community resources to actually learn the math behind it:

1 Like