IK foot placement on uneven terrain: what's your actual production approach?

398 views 11 replies

Been banging my head against foot IK on uneven terrain for the past few weeks and I feel like every tutorial either stops at "just use a raycast" or immediately jumps to some bespoke solution I can't replicate. So I want to know what people are actually shipping with.

My current setup in Unity is pretty standard: two raycasts per foot, lerp the foot IK target toward the hit point, adjust pelvis height based on the lower foot. Works fine on gentle slopes. Falls apart completely on anything with real geometry variation, stairs, rocky ground, sloped ramps with lips. The feet either slide, hyperextend, or the pelvis starts doing this horrible yo-yo thing when the character transitions between different height zones.

head desk

Specific things I'm still not happy with:

  • Foot rotation: matching the foot normal to the ground normal looks great in isolation but creates really unnatural poses when the angle is steep. There has to be a clamp somewhere but where?
  • Pelvis correction speed: if I lerp too fast it looks robotic, too slow and feet float. I've tried tying the speed to movement velocity but it's still not right.
  • Transition blending: when the character steps off a ledge, the IK target suddenly has nowhere to go and the foot snaps. I'm zeroing out IK weight during jumps but the entry/exit is janky.

I've looked at how Unreal's Control Rig handles this with its Full Body IK solver and honestly it seems like a lot of the heavy lifting is just... done for you there. Which makes me wonder if I'm reinventing the wheel in Unity.

Are people writing full custom IK solvers for this, using Animation Rigging package chains, or is there a middleware solution worth paying for? And if you've got a Unity Animation Rigging setup that actually works on complex geometry, please share the general structure, I'll owe you forever.

wow
Replying to PhantomLynx: one thing I haven't seen mentioned here: ankle rotation based on the local surfa...

yes, ankle rotation is the thing that separates "technically working foot IK" from "actually looks good foot IK." the way I do it: project the surface normal into the foot's local space and drive a two-bone rotation, pitch from the forward slope, roll from the lateral slope. blend it by the same weight as your IK so it naturally fades out when the character's airborne. without this the foot just kind of hovers flat against sloped geometry and your eye catches it immediately even if you can't name why.

Replying to PrismBloom: the "just raycast" tutorials kill me because they stop right before the actually...

the simultaneous foot problem is genuinely the hard part and tutorials just don't go there. what worked for me: treat the pelvis as the primary adjustment target and derive foot placement from that, not the other way around. both feet raycast independently, find floor contacts, average the height delta, raise/lower the pelvis to split the difference, then run IK to settle feet. body compensation IS the pelvis movement. not perfect on extreme slopes but avoids the feedback loop you get when feet are driving each other.

reaction
Replying to PrismBloom: the "just raycast" tutorials kill me because they stop right before the actually...

the body compensation part is what kills me too. I found that blending in a separate spine lean based on the slope normal helps a lot. if both feet are planting on a steep incline, the character needs to lean into the hill or it looks like they're standing on flat ground that just happens to be tilted. it's one more thing to tune but it sells the IK way more than getting the foot placement perfect by itself.

thumbs up
Replying to ByteHawk: pelvis-first is definitely the right call, but one thing I'd add: cap your max p...

the deadzone on pelvis vertical is such an underrated fix and I never see it mentioned. another thing I'd add: if you're raycasting for foot targets every frame, consider only updating the IK target when the delta exceeds a small threshold (1-2cm works for me). without that you get constant micro-oscillation on flat terrain too, because your raycast returns slightly different hit normals each frame from floating point variance. the pelvis ends up reacting to noise that isn't real terrain at all.

reaction
Replying to ApexThorn: the simultaneous foot problem is genuinely the hard part and tutorials just don'...

pelvis-first is definitely the right call, but one thing I'd add: cap your max pelvis drop or you get hyperextended knees on steep slopes. I use ~60% of leg length as a hard limit and it kills the "alien legs" look almost entirely. also run the pelvis offset through a smooth damp instead of a raw lerp. lerp pops visually when the player steps off a ledge and the IK correction snaps back to zero.

something I haven't seen in this thread: transition smoothing when the character walks back onto flat ground from uneven terrain. I had foot IK working great on slopes but the snap back to neutral was jarring and looked worse than no IK at all. ended up blending out IK influence over ~0.2s whenever the slope delta drops below a threshold. tiny thing but made a huge difference to how natural it felt

Replying to GlitchCaster: something I haven't seen in this thread: transition smoothing when the character...

the snap-back issue is so real and I'm baffled it's not in more tutorials. fix that worked for me: a separate IK blend weight that ramps 0→1 based on terrain deviation. if the raycast hit normal is more than ~8 degrees off world up, start blending in IK. walking back onto flat ground just reverses the blend over ~0.25s. smooth exit, no pop.

the annoying part is defining "flat" tightly enough that you don't get half-blended weirdness on barely-sloped surfaces. ended up with a small deadzone on the blend trigger and it helped a lot.

reaction
Replying to OnyxLeap: the deadzone on pelvis vertical is such an underrated fix and I never see it men...

the "only update IK target when foot is planted" thing is huge and I wish I'd figured it out earlier. on top of that: I also use a layer mask that excludes the character's own collider from the raycast. spent an embarrassing amount of time debugging foot IK that was planting on the character's own capsule on certain slopes.

also if you're doing this in Unity, Physics.RaycastNonAlloc with a pre-allocated hit buffer instead of Raycast shaves off a surprising amount of GC pressure when you've got a crowd of characters all raycasting every frame.

one thing this whole thread is dancing around but hasn't said directly: foot IK makes or breaks believability, but it will actively hurt you if your animations aren't authored with it in mind. if your base animations already have a lot of foot slide or the foot contact poses are inconsistent, IK will fight the animation instead of completing it. spent way too long tuning an IK system before realizing the real fix was cleaning up the source anims. fixing the wrong thing

the "just raycast" tutorials kill me because they stop right before the actually hard part. what happens when both feet need to adjust at the same time and the body has to compensate? raycast gives you a target position. getting the pelvis to shift naturally while IK is pulling both legs in different directions is a whole separate problem nobody wants to explain.

what's worked for me: two-bone IK per leg as baseline, then layer a pelvis height solver on top that samples both foot targets and adjusts hip height so neither leg exceeds its reach limit. Unity's Animation Rigging TwoBoneIKConstraint is genuinely solid for this if that's your engine. In Godot you're mostly rolling your own or hunting for a plugin that's still maintained.

foot rotation on steep slopes is where I still feel like I'm guessing tbh. I do a surface-normal-aligned rotation lerped by slope angle but past a certain incline it looks off, and I can never tell if it's a math issue or just needs more aggressive smoothing in the lerp.

one thing I haven't seen mentioned here: ankle rotation based on the local surface normal. you can get the foot IK target position sorted but if the foot just sits flat on a sloped surface it still looks completely wrong. the whole sell is the ankle conforming to the slope angle.

what I do: after placing the IK target position via raycast, grab the hit normal and compute a rotation that aligns the foot's up vector to that normal, then slerp toward it with a small lag. works great on gradual slopes. on sharp edges you still need to cap the max deviation or ankles start doing nightmare things.

Moonjump
Forum Search Shader Sandbox
Sign In Register