I'm trying to animate the lock mechanism. So I need each pin to follow the key relief. For this challenge, I made a curve path and give my pin "clamp to" constrain. It follows the path perfectly when I move the key, but it moves not only on the Z-axis. So I add "limit location" constrain to limit X and Y-axis movement. After that pin stays at Z-axis but does not follow the curve exactly. the same story if I copy X and Y coordinate from a static object by "copy location" constrain. I made simplify scene for a better explanation. See gif for more detail. Thanks for any advice.
Thank you all for your advice, they are extremely helpful. "Shrinkwrap" constrain on project mode from Nathan's suggestion works pretty fine if the key angle is not really extreme.
Chris's solution is kind of working, but the key movement is not linear, so it was tricky to make movement for the rest of the pin, and baking animation as an action doesn't help as well. I get a better understanding of constraints thanks to Markus von Broady, now everything is clear. GIF below shows the difference between "Shrinkwrap" (on the right) and baked animation ((on the left))