In my opinion the best way to do this is interacting with your professors.
I think maturing was realizing that I wasn't coming to class for social hour, I was serious about learning. I sat as close to front-row as I could each class; I asked for clarification and even challenged my professors when I didn't understand them; and I attended office hours/recitations. As you start to get up into the advanced sciences, classes go silent (because students are scared of being wrong when answering questions). Professors hate that, because they can't tell if the class is following the lecture. So I became the guy that tries to answer every question. It didn't make me popular with slackers, but the people in the front row with me started following me on my route through the tutoring center and recitation after class, usually after results for the first exam come out.
I started to develop a reputation as the "prepared" student in class, and my professors even started connecting me with other students who were struggling so I could share my study methods. I had even received requests from my professors to recommend them for different awards/tenure.
Internally, professors are emailing each other all the time. Whenever there's a call out for research positions, those professors that know you by name and with whom you interact regularly may just start directly nominating you, including you in e-mail threads, or introducing you to PIs in the halls.
Do this for long enough and you'll have to swing the opportunities away with a baseball bat. Research at the undergraduate level is usually unpaid and tedious. PIs are, in most cases, looking for you to fulfill tasks anyone could do. That said, you have to be really careful about who you trust to take up a research position with. You are looking for a lab that is productive (the lab produces several papers over the course of a year), inclusive (undergraduates like you are listed as authors on those papers), and instructive (the PI is interested in teaching you how research is conducted and how to engage with graduate students and academia more broadly). That's a really tall order, and it's harder to find than you might think. It's better to overthink and avoid a crisis than underthink and have to confront the crisis after you've put all your eggs in one basket.
Sadly, I ran into people who just genuinely felt only PhD-track students should be doing research and saying you're going MD is interpreted as "selling out." That doesn't mean they won't accept you into the lab, it just means that the posters, presentations, and authorship that you're looking for are actually going to go to PhD-track students because they think "you don't need it." These kinds of folks are (in their own minds) not intentionally malicious, just misguided about what it takes to get into medical school...and their misconceptions can definitely hurt you.
DO NOT abandon your classwork because your PI thinks you should do x,y,z first. My junior year, I didn't take finals during an important week in the lab because my PI said "I know your professors, you can take them next week." Next week came around and they turned around and said "I never said that!" I had to withdraw from the entire semester and left the lab in tears, after having worked 14-hour days for a week straight (and for years prior to that), for free, on a pinky promise. Raising alarms and notifying the school led nowhere; writing formal complaints led nowhere; there really is no accountability, especially for tenured professors. Given I had financial issues attending school at the time, the withdrawals meant I couldn't fund my retakes, and that led me to leave school for over a decade. Edit: I thought it would be important to note that karma would not strike for many years thereafter. This tenured professor was eventually terminated for unrelated (but similar) causes in the last two years. Rare, but real.
You can do everything right and still fail. Be warned. Educate yourself. Make good choices. Good luck!