# How to make polygons hitboxes accurate, and how to import rotation values into python

**URL:** https://discourse.mapeditor.org/t/how-to-make-polygons-hitboxes-accurate-and-how-to-import-rotation-values-into-python/6482
**Category:** Questions
**Created:** [December 31, 2023, 2:07pm UTC](https://discourse.mapeditor.org/t/how-to-make-polygons-hitboxes-accurate-and-how-to-import-rotation-values-into-python/6482 "2023-12-31T14:07:17Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Kaiden](https://avatars.discourse-cdn.com/v4/letter/k/4af34b/32.png) [@Kaiden](https://discourse.mapeditor.org/u/Kaiden)
#### Post date: [December 31, 2023, 2:07pm UTC](https://discourse.mapeditor.org/t/how-to-make-polygons-hitboxes-accurate-and-how-to-import-rotation-values-into-python/6482/1 "2023-12-31T14:07:17Z")

</div>

So im making a game in python with the pygame module, and im using tiled to create my map with pytmx to interpret the map. The game i am making is a racing game, and i dont want my player to be able to leave the track, but i am struggling to get the hitboxes to work correctly. As i am new to both python and tiled, im not sure on how to fix my issues.

The first issue which doesnt include python, is the hitboxes with the polygons as i can draw a shape, but the hitbox is just a big rectangle.

 ![image](https://canada1.discourse-cdn.com/flex035/uploads/mapeditor/original/2X/b/b5ea33efe6d6f7d209d4b72ba12232c6445f1b6b.png)  
As you can see, the hitbox is the rectangle around the triangle, but i want the hitbox to match to polygon. In the game, with the hitboxes made visible for bug testing, the hitbox is also a rectangle. If this is intentional and there is no way to match the hitbox to the polygon, then i instead could used rotated rectangles.

However, this is the second issue, which i assume is happening due to the lack of my python knowledge.

 ![image](https://canada1.discourse-cdn.com/flex035/uploads/mapeditor/original/2X/d/d2bb49ff8212c63c4835a27ccd6c521f3942ee74.png)  
This image is showing a curve in the track, with thin rotated rectangles for hitboxes, however in game they look like this  
 ![image](https://canada1.discourse-cdn.com/flex035/uploads/mapeditor/original/2X/c/c1cba1b45af92a5fe95d11380637ea29ebfa555f.png)

---

<div class="post-metadata">

### Author: ![eishiya](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.mapeditor.org/eishiya/32/2534_2.png) [@eishiya](https://discourse.mapeditor.org/u/eishiya)
#### Post date: [December 31, 2023, 2:17pm UTC](https://discourse.mapeditor.org/t/how-to-make-polygons-hitboxes-accurate-and-how-to-import-rotation-values-into-python/6482/2 "2023-12-31T14:17:58Z")

</div>

Your screenshot of the triangle just shows the resize handles - those are based on the bounding box, but the triangle in your file is the actual triangle you drew. Read in the polygon and use it, you do not have to use its bounding box.

Unfortunately I can’t help with the Python side of this. Check the documentation for the Tiled map loader you’re using regarding rotation, and for the physics system you’re using (whether it’s built into Pygame or something separate).

---

<div class="post-metadata">

### Author: ![Kaiden](https://avatars.discourse-cdn.com/v4/letter/k/4af34b/32.png) [@Kaiden](https://discourse.mapeditor.org/u/Kaiden)
#### Post date: [December 31, 2023, 4:11pm UTC](https://discourse.mapeditor.org/t/how-to-make-polygons-hitboxes-accurate-and-how-to-import-rotation-values-into-python/6482/3 "2023-12-31T16:11:04Z")

</div>

Ive had a look through the docs, and tested multiple things but i cant figure this polygon thing out for the life of me, i am going to try github or stack overflow and see what info i can get  
Thanks for the advice 🙂

---

<div class="post-metadata">

### Author: ![eishiya](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.mapeditor.org/eishiya/32/2534_2.png) [@eishiya](https://discourse.mapeditor.org/u/eishiya)
#### Post date: [December 31, 2023, 4:18pm UTC](https://discourse.mapeditor.org/t/how-to-make-polygons-hitboxes-accurate-and-how-to-import-rotation-values-into-python/6482/4 "2023-12-31T16:18:00Z")

</div>

If you’re using PyTMX to load maps, the objects should have an `as_points` property, which presumably has the list of points that make up the Object. This is what you would use to construct your in-engine triangle.  
There is also `apply_transformations() `, which returns a list of points for the object after taking rotation into account, you’d probably want this for both your triangles and your rotated rectangles.

Source: [pytmx package — pytmx stable documentation](https://pytmx.readthedocs.io/en/latest/contents.html#pytmx.pytmx.TiledObject)

---

<div class="post-metadata">

### Author: ![9o79o7](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.mapeditor.org/9o79o7/32/5381_2.png) [@9o79o7](https://discourse.mapeditor.org/u/9o79o7)
#### Post date: [May 5, 2026, 10:55pm UTC](https://discourse.mapeditor.org/t/how-to-make-polygons-hitboxes-accurate-and-how-to-import-rotation-values-into-python/6482/5 "2026-05-05T22:55:20Z")

</div>

Why is this also accurate to how the Geometry Dash editor works?
