I assume you are not using the physics system and trying to do your own collision? If you are using physics, enable continuous dynamic collisions and it should Just Work™.
Some other ideas;
- keep a previous AND a current collider for the black (or the orange) object, chasing it along with a one-frame delay. This would only up your raycast count to 2: either 2 raycasts from 2 orange positions, OR two raycasts against two target colliders.
You can actually raycast against the two specific colliders directly with Collider.Raycast (or Collider2D.Raycast() ) to further simplify the problem, or use layering to keep the ghost object from interacting with anything else.
Raycasting, colliders, planes, Plane, etc:
- another way is forego raycasting and just iterate the “enough” steps between the orange object’s move frames, checking with either Overlap() calls or just checking coordinates for closeness. The term “enough” would be approximately one plus the maximum movement magnitude divided by the smaller collider’s size.