Why do we use "at" in the phrase "good at [doing]"

Preposition at is often used in the following context:

to show the activity in which someone's ability is being judged:

  • I was never very good at sports. He's very good at getting on with people. She's hopeless at organizing things.

but also

to show the cause of something, especially a feeling:

  • We were surprised at the news. I was quite excited at the prospect. Why does no one ever laugh at my jokes?

(Cambridge Dictionary)