The problem is an autofocus camera doesn't know what exactly you're trying to shoot when it's on something thin or fine (like a twig or fennel leaf). 90% of the frame is dominated by the background, so it focuses on that. Depending on the camera, there are a few options that might help.
Most point-and-shoot-type cameras can use either a single focus point (usually right in the middle of the screen) or several points. The latter is often the default setting, but the single point is better in the case you describe. Check your manual to see if you have that option, and how to change it.
If your camera has a "macro" mode make sure you are using it. That tells the camera you are trying to shoot something very close, so if the caterpillar is close, and the background is relatively far away, it will hopefully be biased for focusing on the nearby object.
Most cameras, even the less expensive ones, have some kind of manual focus feature. The problem is it can be difficult to find and use. But if it has it, you can use that to set the focus instead of letting the camera do it.
Finally, a "cheat" I often use is a feature generally called "focus lock" or something like that. If you can get the camera to focus on something at about the right distance, you can push a button and lock the focus at that point until you take the picture. So, for example, you could focus on your hand or some other flat, even surface that the camera can easily focus on. Then hit the lock, and swing the camera over and position it at the same distance from the intended subject. Once in focus, take the pic. That's what I use on my iPhone (which has no manual focus feature). Even when I had my point-and-shoot cameras, I found that quicker and easier than trying to mess with the clunky autofocus.