How do I negate the rotation that is added onto the Ankle Motor6D by the Hip and Knee Motor6D’s? I need the foot to always stay flat on the ground no matter the rotation of the whole leg. I’ve already tried to take away their rotations from the ankle rotation, but it didn’t work the way I expected it will
local x1, y1, z1 = rightHip.C0:toEulerAnglesXYZ()
local rotation1 = CFrame.Angles(-x1, -y1, -z1)
local x2, y2, z2 = rightKnee.C0:toEulerAnglesXYZ()
local rotation2 = CFrame.Angles(-x2, -y2, -z2)
rightFoot.RightAnkle.C0 = defaultRightAnkleC0 * rotation1 * rotation2
It looks pretty good on some surfaces, but when the leg is up high it doesn’t work at all
Try removing the X and Z rotations. Because removing all rotation means the shoe will always point in the same direction, while you need it to point forwards, which I believe is the Y rotation.
The foot’s upVector is equal to the ground’s normal.
Use the leg’s rotation to work out the other axes.
-- n = surface normal
-- r = leg's rightVector
local function footRotation(n, r)
local back = cross(r, n).unit
local right = cross(n, back)
return fromAxes(right, n, back)
end
fromAxes
local function fromAxes(vx, vy, vz)
return CFrame.new(
0, 0, 0,
vx.x, vy.x, vz.x,
vx.y, vy.y, vz.y,
vx.z, vy.z, vz.z)
end