Just working on tile collision and thought I'd share my method for people curious on how to do tile physics. There is a map class that takes care of the collision. The heart of it is the customizable callbacks called the preSolve and postSolve. With the callbacks, you can do neat things like one way tiles in the example. Collision detection is done by using the edges of a bounding box as vertical or horizontal sensors.
I know there's plenty of tile collision examples, but I wanted to post one with minimal amounts of code
Things to do:
* Slopes
In the demo:
Try changing the tile size or player box size! It'll work for any size! Try defining your own custom callback for neat stuff like destructible tiles or bouncy tiles.
Hope it helps!
Updates will be posted here:
Git Repo
Re: Tile collision example
- dreadkillz
- Party member
- Posts: 223
- Joined: Sun Mar 04, 2012 2:04 pm
- Location: USA
Tile collision example
- Attachments
-
- tile collision.love
- Arrows to move
- (3.18 KiB) Downloaded 904 times
Re: Tile collision example
Update! It now supports slopes and continuous collision detection. Syntax is similar to my lib: ATC, except you don't need Tiled. Just feed it a grid structure and a table with tile properties. Modify it however you want!
- Attachments
-
- tile-collision.love
- (2.76 KiB) Downloaded 585 times
Tile collision 1.0
Just a bump for the update. Slope example is in my ATC demo, sorry! It's quite similar in code so hopefully you can figure it out.
For those who want to learn:
http://info.sonicretro.org/SPG:Solid_Tiles
http://forums.nesdev.com/viewtopic.php?f=2&t=6319
The difference in methodology from the posted links is that my sensors are the actual box edges so it's possible to miss tiles completely contained with a rectangle. This shouldn't be an issue when character movement is small enough for a sensor to catch collision tiles.
Slopes and curves are handled like retro games: Store an array of height values per slope tile. How the player reacts to the tile and the direction he needs to be pushed to resolve the collision depends on which sensor touches it.
I took the route of using the box corners to resolve slope collisions instead of the midpoints of each side. This has the problem of a character sticking out from a slope more instead of looking like he is standing on it with his "feet". Many old games covered this up visually by extending the slope.
For those who want to learn:
http://info.sonicretro.org/SPG:Solid_Tiles
http://forums.nesdev.com/viewtopic.php?f=2&t=6319
The difference in methodology from the posted links is that my sensors are the actual box edges so it's possible to miss tiles completely contained with a rectangle. This shouldn't be an issue when character movement is small enough for a sensor to catch collision tiles.
Slopes and curves are handled like retro games: Store an array of height values per slope tile. How the player reacts to the tile and the direction he needs to be pushed to resolve the collision depends on which sensor touches it.
I took the route of using the box corners to resolve slope collisions instead of the midpoints of each side. This has the problem of a character sticking out from a slope more instead of looking like he is standing on it with his "feet". Many old games covered this up visually by extending the slope.
Re: Tile collision example
nice work, better than my code
Re: Tile collision example
Are slopes implemented yet? I can't figure out how to make one.
Re: Tile collision example
Here's an updated demo with the slopes. Each slope tile has an associated height map that determines the shape of the slope. It's similar to the Sonic physics link.lieudusty wrote:Are slopes implemented yet? I can't figure out how to make one.
- Attachments
-
- demo+slopes.love
- (3.37 KiB) Downloaded 418 times
Re: Tile collision example
I updated the module to version 3. You no longer have to create a box object. Instead, you create a handler object and pass the dimensions of your box to it for collision resolution. A lot of extraneous functions were also removed. It's much more flexible now so it should work with any map format, even Advanced Tiled Loader.
The repo is the same as above.
The repo is the same as above.
- Attachments
-
- demoV3.love
- Arrows to move.
- (4.41 KiB) Downloaded 600 times
Re: Tile collision example
Hey, your collision detection is amazing but I'm not used to using entities, so could I ask how you'd bound images to an entity like you've made and then apply physics to it? I've essentially got code that doesn't have collision detection but can use images as the player character and has gravity applied to it, then there's this code that has great collision detection but I don't know how to change the player from a square to an image or how to apply gravity to it, so that it works the same way as a traditional platformer.
Re: Tile collision example
Or if it's possible to use the tile collision and bind it to the world from the physics tutorial, that'd really help too!
Who is online
Users browsing this forum: No registered users and 0 guests