2D in-game companion system

Well, I’m not sure how to make a smart system in my Shootemup game where the player always has a buddy as an ally.

Before, I just used lerp to change the buddy’s position, but I know that’s not very smart if there are walls. So I made a system where there are nine points around the player, and the buddy goes to each one if it doesn’t hit a wall.

But it seems like there are smarter and smoother ways to do this. I’ve heard about raycasting and distance joints. I tried to apply both to my game, but I couldn’t get it to work. What would be the best option, and how can I apply it?

I tried to apply the distance joint, but it seems to affect the player’s movement.

Top-down or platform or other.

Platform shoot 'em up.