This is a continuous collision problem. The "bullet through paper" problem as most refer to it. I'm not sure how you implemented your system, your question could use more details. But it sounds like you're discretely checking collision. Basically in the example below:
The ball never intersects the rectangle since it's doing a basic intersection test every iteration. There's lots of ways to battle this. It's called continuous collision detection. Raycasting can produce some results. But there are many use cases where unless you shot infinite rays out of the circle you wouldn't be able to use it. Consider the examples below:
This is where shooting one ray or even two would break. What you need is too model the area the shape will take as it moves. Like so:
Above shows the blue area that needs too be checked. So calculate the area to be checked and then if it is intersecting you need to calculate where to resolve the ball too on the rectangle. The resolve is the hard part.
Obviously CCD (continous collision detection) is costly and in fact not used in many games/applications. But sometimes it is needed to produce acceptable results.
You can get around using CCD by using smaller velocities ensuring none of your objects are able to pass through one another.