Legs are good for one thing: agility
Have you ever watched two boxers fight? I mean really watched what they were doing? Credit to everything on the human body, but it could be said that boxing is about your legs. They're used to:
- Keep your balance
- Shift your weight for leverage and strength
- Move you deftly out of harm's way or into a superior position in almost any direction.
So your spider mech has an advantage over wheeled or (worse) tread tanks in that it can better keep its balance, hop out of harm's way, perhaps even right itself when knocked over (if they're designed well). Have you ever tried to tip an Abrams back on its treads? I haven't, but I bet it takes more than a couple of big Tongans to do it.
At literally everything else, legs stink
I'm assuming we're comparing apples to apples by talking about manned mechs. The arguments for drones are very, very different because you can make the mech (comparatively) very, very small. Wheels/treads are great when there's enough weight to keep them solidly in touch with the ground. They're less valuable when the object being moved is very light.
(1) Let's add some armor to that boxer. And a big ol' gun. Let's let him look a bit like the combat dudes from StarCraft.1 Suddenly you're having to add all kinds of mechanical enhancement to the armor — and you'd think you're doing that to enhance the combat abilities of the wearer, but you're spending most of the energy just moving the armor.
In the same way that most of your gasoline is being used to move the car... not you.
So, the more armor you add to the mech, the less valuable the legs become because adding enhancement to overcome the weight is seriously a losing battle. As armor increases, the mechanics to move the armor increases, the fuel needed to power the mechanics increases, all of which adds stress to complicated joints... and all you really wanted to do was kick the other guy's butt.2
Armor almost always succumbs to armament. You don't see plate mail anymore because rifles pack enough punch at enough distance that you might as well be standing there begging them to shoot you ... which is what you'd actually be doing.
(2) Now let's add tree roots, bushes, things that are easily squashed and driven over with wheels and treads but are an amazing hang-up for legs. The issue isn't tripping, the issue is the inability to move a hung-up leg forward, which means you're a sitting duck.3
(3) And your center of gravity, which is high for anything with legs but low for (almost anything) with wheels or treads (monster trucks violate this rule... but that's outside the scope of your question). A high center of gravity means it's easier to make the unit unbalanced, tip it over, or control it with trip wires (see my last point). It also raises the unit unecessarily high off the ground, making it an easier target.
(4) Then think about speed. This is where legs really, really stink. It doesn't matter how much you enhance joints, wheels and treads can always out run legs.
(5) Finally, add to this the increased complexity of affecting knees, ankles, hips, rotor cuffs, tendons, muscles, and a whole lot more. There's an engineering axiom that, frankly, should be considered a Universal Law.
KISS: Keep it simple, stupid!
Those cool mechs, gundam, and all other things robotic used to fight Godzilla and who knows what else from the 8th Dimension and Beyond are just that... cool... and absolutely useless. Complicated design and automation that can only be driven by an operator with a PhD in physics costing bazillions of dollars and it's all wasted by a single shot from some crazy dude with a big ol' gun that cost pennies on the dollar to build compared to your mech and that can be aimed and fired by a 10-year-old hiding behind a rock.
So, looks cool in anime, but in real life the cost-to-value ratio is way, way, way in favor of wheels and treads. If you really want mechs in your story, you need to do what all previous authors have done... you need to declare it to be so and move on with the story, because you'll never be able to justify the tech.
1 Which, if you think about it, is so unbelievably unrealistic that it makes angels weep. Think about how far you'd have to dislocate your sholders to get them into the arms, etc. But, it's a heckuva game to play, so no complaints. Nosireebob.
2 An astute observer might claim that the same is true for wheeled vehicles and tanks. That's true, but not to the degree of moving joints. It's relatively easy to increase engine size to turn a more heavily loaded axel compared to all that needs to be done to move 2–3 joints. If the problem increases geometrically for tanks, it increases exponentially for mecha.
3 If you don't believe me, the next time you get your foot stuck in some brambles stop and really think about what your brain can do with your foot pretty much unconsiously — you twist them, rotate them, tip and tilt them... and still you occasionally get your feet stuck. What the human brain can do with a foot is almost as breathtaking as the enormous effort it takes us to simulate it artificially — and we still can't build a robot that does it as well.