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

How do I get Motors to rotate on more than one axis?

Asked by
Scriptecx 124
8 years ago

I have been looking at this foot planting script by AxisAngle and I was wondering how he got the joints of the legs to rotate on more than just one axis using the motor6Ds in the torso of the character. My question is how do I calculate the C0 and C1 of the joints to get it to rotate on the axis I want it to? If that makes any sense? I can't really wrap my head around the math behind the script and I was wondering if anyone could help me. Here is his script.

--Script by TreyReynolds

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

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
    wait()
    if Torso.Velocity.magnitude > 1 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, R_a, 0)
        R_Hip.C1 = CFrame.new(0, 1, 0)*CFrame.Angles(0, L_a, 0)
        L_Hip.C0 = CFrame.new(-0.5, -1, 0)*CFrame.Angles(0, R_a, 0)
        R_Hip.C0 = CFrame.new(0.5, -1, 0)*CFrame.Angles(0, L_a, 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

Answer this question