Answer the question
In order to leave comments, you need to log in
How to calculate the presence of obstacles on the way in a 2d world?
There is an array of 2d objects (mostly rectangles and squares).
It is necessary to calculate whether there is one of the objects in the path of the projectile.
Now I'm checking for the presence of objects in the triangle ABC , where the median AM is the path of the projectile. I took 30°
around corner A.
The problem is that objects are two-dimensional and have different widths and lengths.
The algorithm fails when the object is too wide, but its center goes beyond the area of the triangle.
I thought about evenly applying points to the path and checking the entry of the object into these points, but I have no experience in this area.
How to solve this problem correctly?
Answer the question
In order to leave comments, you need to log in
See how they are set. Perhaps the easiest way is to calculate whether the segment "the beginning of the flight of the projectile - the end of the flight of the projectile" intersects on each side of the 2d objects. If it intersects, then kirdyk. You just need to decide what to do if this segment crosses the top of the obstacle.
We need to take the equation of the straight line of the projectile flight segment and check whether any of the sides of the polygons that bound the 2d-obstacles lie in different half-planes from this straight line. If so, then there is an intersection.
In my opinion, this is done by multiplying vectors, but I could be wrong, you have to google it.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question