Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do we make Inverse Kinematics?

Asked by 4 years ago
Edited by Gey4Jesus69 4 years ago

Please encode Lua code in the Lua block code tag (look for the Lua icon in the editor).

I never asked for the damn code mods so don't even try closing this. Just need some help with IK kinematics (aka dynamic movement) the problem is I don't know how the hell to make it and I get errors in the process of the code.

Code:

wait(1)
User = game.Players.LocalPlayer
Humanoid = User.Character.Humanoid
Torso = User.Character.LowerTorso
L_Hip = Torso["Left Hip"]
R_Hip = Torso["Right Hip"]

local step = game:GetService('RunService').RenderStepped;

function ArcTan(x, y)
    r = math.atan(y / x)
if x < 0 then
    r = r + math.pi
end
return r
end

vel = Vector3.new()
while true do
    step:wait()
    local velVector = Vector3.new(Torso.Velocity.X,0,Torso.Velocity.Z);
    if velVector.magnitude > 0 then
        m = (vel - Torso.Velocity).magnitude / Humanoid.WalkSpeed
        vel = (Torso.Velocity * m + vel * 2) / (m + 2)
        v = Torso.CFrame:pointToObjectSpace(vel + Torso.Position)
        L_a = ArcTan(v.x, -v.z)
        R_a = 3.1416 - ArcTan(v.x, v.z)
        L_Hip.C1 = CFrame.new(0, 1, 0)*CFrame.Angles(0, L_a+math.pi, 0)
        R_Hip.C1 = CFrame.new(0, 1, 0)*CFrame.Angles(0, R_a+math.pi, 0)
        L_Hip.C0 = CFrame.new(-0.5, -1, 0)*CFrame.Angles(0, L_a-math.pi, 0)
        R_Hip.C0 = CFrame.new(0.5, -1, 0)*CFrame.Angles(0, R_a-math.pi, 0)
        L_Hip.MaxVelocity = Torso.Velocity.magnitude / 100
        R_Hip.MaxVelocity = Torso.Velocity.magnitude / 100
    else
        L_Hip.C1 = CFrame.new(0, 1, 0)*CFrame.Angles(0, -1.57, 0)
        R_Hip.C1 = CFrame.new(0, 1, 0)*CFrame.Angles(0, 1.57, 0)
        L_Hip.C0 = CFrame.new(-0.5, -1, 0)*CFrame.Angles(0, -1.57, 0)
        R_Hip.C0 = CFrame.new(0.5, -1, 0)*CFrame.Angles(0, 1.57, 0)
    end
end
0
ok swearing obviously won't help your case Gey4Jesus69 2705 — 4y
0
i said hell? DayLighter_1995 8 — 4y
0
Could you maybe tone down getting my comments removed for asking help? DayLighter_1995 8 — 4y
0
"I get errors in the process of the code", yet you show no code. how do you expect to get help if you dont explain the issue? if you don't understand it at all, search the wiki and the devforum. your question is so unbelievably broad that you cant actually expect someone to answer it Gey4Jesus69 2705 — 4y
View all comments (7 more)
0
I did it. didn't you see? I did it on all of the posts I made? how'd you not see it? DayLighter_1995 8 — 4y
0
What I think is wrong is the Motor6D's DayLighter_1995 8 — 4y
0
yeah this code is totally on all your other posts Gey4Jesus69 2705 — 4y
0
It may have been a glitch. Don't wanna make a scene but your being a bit disrespectful.. DayLighter_1995 8 — 4y
0
*facepalm* Gey4Jesus69 2705 — 4y
0
Bro would you stop commenting I just wanted to make foot planting.. DayLighter_1995 8 — 4y
0
how 2 be a shitty mod DayLighter_1995 8 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago

Quick Lil' Update, I think the motor6d's are just wrong and I think I may have named the whole thing wrong, sorry!

Ad

Answer this question