-
Notifications
You must be signed in to change notification settings - Fork 5
This Week in LesserPanda #1
Covering the week of 2016-04-13 to 2016-04-20.
Since LesserPanda laces of document and I don't have much time work on it yet, a samples repo may be helpful to new comers. The samples repo is a simple game project without a index page, you still need to make small changes to launch other samples than the default one.
Currently the default sample is Tilemap with collision debug display.
This weeks major task is to improve the Tilemap
module, and the progress is good so far. Now it's possible to load maps generated from Tiled, and be able to collide.
Change highlights:
- Tiled map importor
- Collision maps will be automatically compiled to convex polygons and supported by SAT collision solver
Since the design of Tiled map is different from built-in Tilemap, you need to do some extra steps to make it work. See inline comments of tilemap
module for more detailed information.
This may be the most complex thing inside LesserPanda. I've tried 2 different algorithms, and finally got it work.
There're a draft I posted on Trello a few weeks ago about how the tilemap collision would be supported. And last week I decided to dive into collision map compilation that create collision shapes directly from the map instead of drawing it manually.
Some other game engines may let the objects collide directly with tiles, which you might think is better. But sometimes I just forgot which tile is solid which is not, and when I want to create secret rooms but still keep the same tile on top of that, Tile based collision won't work any more.
Someone may ask why don't let objects collide with each collision tile. Well I did think about it, see the draft I mentioned before. But we already have polygon collision support, and the great Tiled2Unity inspires.
At the beginning, I think it's not necessary to compile tiles into polygons since we can also collide line segments.
And here's the result:
Every line segment is a physics body, and it looks pretty nice until I found that collision at the corner does not feel right. That is because the lines collide both sides, and when a body is at the corner of two lines, you won't be able know what is actually happening.
After experimenting lots of possible solutions, I decided to dive it deeply, by compiling the line segments into convex polygons.
This brings optimization (less bodies) and solves the corner collision issues caused by line segments (from algorithm v1).
Now the collision map looks like this:
The core is finished, but can still be optimized a lot. So I am going to work on that first.