Check collisions along the path

I just started with monogame (2d), and I am stuck at one problem.

I want to move one object (circle) from one point to another.
First I am selecting my object, then I am clicking at destiantion point, and now I want to check if there is anything between start point and destination.

I would be grateful for any help, because I don’t even know how to start with that one…

Since you treat your object as a circle I’m assuming you also treat your collision objects as circles.

The easiest approach is probably to loop over all your collision objects. For each collision object you calculate the point on the movement-line that is closest to the collision object. This is the point where the object will be closest to the collision object, as it moves along the line towards the destination.
If a collision is happening at all, it will certainly happen at that point. If there is no collision at that point, there won’t be a collision at any other point.
A collision is happening if the distance between this “point of closest approach” and the center of the collision object is smaller than objectRadius + collisionObjectRadius.
Calculating the closest point on a line is a math problem that’s easy to google a solution for, see here for example:

1 Like

I’m sorry. It’s rather late here in Austria.
I’d recommend my link-list here:

Then, perhaps start with basic geometry like that:
Before I’d go for the Separating Axis Theorem (not as hard as it sounds) here:

The problem with your description is, that there are several ways a circle can intersect with another object (maybe another circle). They would touch (entry) very slightly, before ‘moving through each other’ and just before they stop colliding, they would barely touch (exit) again. You can calculate that (the points in time when entry and exit happens).

And when you take into account that one of them (or maybe both) moves faster that your sampling-rate, then it gets even more complicated. That’s called a sweep test. Personally I would go for that.
Then you’re here:
or here:

…And… of course … what @markus says … :smile:

1 Like

Thank you guys for tips how to solve that :slight_smile: