SFML Bounding Box Collision Detection

微笑、不失礼 提交于 2019-12-05 19:20:30

Hazarding a guess, I'd say that rotation of the object is the culprit, as rotation has the unfortunate effect of expanding the bounds of an object. The bounding rectangle after rotation is still in the x-y plane determined by the screen, but encompasses the object post-rotation. As illustration, look at the global bounding box on text in this picture:

Note that the box surrounds the object, but isn't the rotated version of the original bounding box that you might expect to get. In the words of the tutorial on graphics transforms:

SFML entities can give you their bounding box. The bounding box is the minimal rectangle that contains the entity, with sides aligned on the X and Y axes.

To solve this issue, you might try creating a rectangle that will always be wholly contained inside the visible parts of the object, and then use that for hit detection instead of the object's bounding box.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!