Negate CFrame from CFrame?

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

image

image

1 Like

If you’re trying to set it relative to another part’s cframe, then just multiply that part’s cframe by the offset of your desired one for the foot.

Otherwise, you can just reconstruct the cframe using its position:

foot.CFrame = CFrame.new(foot.CFrame.p)

2 Likes

What I’m trying to do is make it so the foot is always pointing at the floor like this

image

but I can’t just set the C0 of the Ankle Motor6D to CFrame.new(0,0,0) because that’s not how it works.

I tried to take away the rotations of the Hip and Knee C0’s from the Ankle C0, but it didn’t work properly.

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

https://my.mixtape.moe/nxaylj.webm

6 Likes