Best way to make walking animation interact with terrain

Hello!

I’ve created a custom creature made out of cubes that I’ve been trying to animate. I wish to make it walk in such a way that it’s legs would interact with terrain (for example, they would stand on top of smaller obstacles on the path instead of warping through them) but make it not actually influence the movement of the entire thing (I wish to keep that handled seperately).

My current setup involves the “torso” and “feet”, with the legs in between rigged up with character and hinge joints.

So far I’ve tried making an animation using the Unity’s animation tab, but I was unable to make the legs interact the way as described above.

I’m currently working on animating it using the .MovePosition, where I give each foot 4 points determined by a Vector 3 relative to the parent “torso” and make it cycle through them. It’s been pretty successfull but I noticed that the points do not update apropriately if I rotate the whole thing (they instead continue walking in a crab-like fashion).

I would appreciate if anyone has any suggestions for either approach.

To my knowledge there are two approaches you could use here, the first is a lot simpler, and may provide you with enough, the second is far more complex, in any case I’ll just give a brief overview here since otherwise it could be an insanely long post.

  1. Have a standard movement animation, you let the animation play, and then after the animator does its thing you jump in (during LateUpdate), raycast to find the “floor” position for each foot, and then use some IK to then adjust the rest of the limb based on the joints. Unity does have some IK stuff built in I think as part of mecanim (please someone correct me if I’m wrong there) but not sure if it work on non-humanoid rigs (again, not much experience with that so again anyone with more info please chime in).

  2. Do all of the animation procedural. Now this I’ve had to do before for spiders and here’s how it breaks down. you have to have a means of calculating the “arc” that you want a foot to travel, then by means of an update coroutine or some other method, you move a given foot (depending on which feet are active at any time) along the arc (and as before, use IK to correct the rest of the limb after setting the new foot position), each time checking to see if you’ve come into contact with the floor, if so, that foot is marked as grounded and you wait until the next footstep time for that particular foot, rinse and repeat. This can be a really cool way to move creatures as you can get all sorts of control over the gait (the pattern/style of the walk) by controlling variables like making the arcs longer, shorter, taller, flatter, less or more time between each legs steps and the step speed itself. That all being said, this method is a hell of a lot more complex, and can result in some really interesting visual bugs later down the line (something I often referred to for the spiders as “space-squidding”).

Sorry for not going into more detail, but hopefully this gives you an idea of some options, and perhaps someone else can chime in with more ideas If there’s something I missed (there’s always something I miss).