Tips on making Footprints

[If you don’t already understand raycasts to some degree, you likely wont understand this]

Recently, I was making a footstep/footprint system for my game. And I realized that making footprints was harder than expected, because I wanted my footprints to not only line up with the ground (so when on a slope, they aligned with the surface) but also to line up with the character (so turning would cause the footprints to turn aswell). And getting both of these was, like I said harder than expected. Especially because I could find absolutely zero documentation on how to do this on the forums here. So here is how I did it.

This is fairly short as I’m just explaining my solution behind this, not the whole footstep system I wrote.
So let’s assume that you’ve raycasted down from wherever your making the footprint (in this case, let’s say the position of my right leg) and we’ve hit the floor. The only things we care about here is the position and normal of the raycast. The position the raycast returns is the point where the raycast intersected the ground, which is where we place our footprint. Then we’ll want it to line up with the normal while facing the same direction as the character, so we can do this via:
(Result is what the raycast returns)

local LookVector = Result.Normal:Cross(HumanoidRootPart.CFrame.RightVector)
--//What we just did was taking the normal of the ground and the characters
--RightVector and Crossed them, which produces the missing LookVector needed to
--Make a CFrame from them, we do this instead of using the characters LookVector
--To account for slopes.
Footprint.CFrame = CFrame.lookAt(Result.Position, Result.Position+LookVector, Result.Normal)
--//The lookAt function can take 3 inputs, Position, The Position to look at, and
--the UpVector to use. By using the faces normal as the UpVector we can account for
--Yaw, which normally would be ignored by just using the LookVector we made
--Earlier. Now we have a Footprint part positioned and rotated according to
--Both the character and ground.

I really hope this saves someones time, and feel free to ask questions.

12 Likes