Raycast bullet collision problem

So i have been developing this classic game for training where the player is shooting bullets to some weirdly-shaped enemies. Initially, i had the very common problem of bullets going way too fast through some collider which is not triggered when the bullet passes through it (this target is not solid). So i implemented the raycast test which basically creates a raycast between the position of the bullet in the current frame, and the position of bullet in the previous frame, checking for collision hits. This step worked fine, but raycast lead me to another problem: The edges/borders of this target ARE solid (just like a ring or torus, if the bullet collides with the borders then the bullet may ricochet in or out of target area). So, if the bullet ricochets OUT of the target area, the constantly-moving ring may still catch up with the previous position of the bullet when it ricochet. In other words, suppose frame A is exactly when the bullet collides with the ring border at position P, the next frame B the bullet is ricochet out of the ring and not in touch with the borders anymore, meanwhile the ring target area has moved into position P, therefore raycast hit between frames A and B will find a collission.

How can i overcome this problem?
Hope i made myself clear, Thank you in advance

“bullet in the current frame, and the position of bullet in the previous frame”

" the bullet may ricochet "

I believe this combination may be a part of your troubles. Consider; if the bullet hits the border and ricochets at a time that is halfway between two frames. In this case, the line between the bullet position, in each frame will NOT include the target.

I would suggest you leave everything in the “current” frame; Compute the bullets position, assuming it moves in a straight line, at the end of the frame yourself, the formula for that is simply: (position + (velocity*frametime))

Use that as your final point for the raycast, (and current position as raycast start), and check the raycasts against the current position of objects in the scene.

Alternatively, you can COMPUTE the bullets last-frame position, using the same method. (again the advantage to computing over recording it, is you know you are computing a straight line, with no bounce.)