Unexpected behavior with collide_and_get_contacts

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Alfredo Oltra

Hi!

I’m trying to get the contact points between a RectangleShape2D and a SegmentShape2D. I’m using the collide_and_get_contacts function. The problem is that sometimes the result is not as expected.

In the attached gif you can see that when the segment is completely inside the rectangle one of the points does not mark the end of the segment but the intersection between the segment’s extension and the rectangle.

error 1

Something similar happens when the segment is larger than the rectangle and the points of contact are two.

error 2

Is it an engine error or should I follow another way (maybe clipping techniques) to get what I want? In that case, how could I solve it?

Thanks in advance