Re: Tile collision example

Showcase your libraries, tools and other projects that help your fellow love users.
Post Reply
User avatar
dreadkillz
Party member
Posts: 223
Joined: Sun Mar 04, 2012 2:04 pm
Location: USA

Tile collision example

Post by dreadkillz »

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
Attachments
tile collision.love
Arrows to move
(3.18 KiB) Downloaded 873 times
User avatar
markgo
Party member
Posts: 190
Joined: Sat Jan 05, 2013 12:21 am
Location: USA

Re: Tile collision example

Post by markgo »

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 546 times
User avatar
markgo
Party member
Posts: 190
Joined: Sat Jan 05, 2013 12:21 am
Location: USA

Tile collision 1.0

Post by markgo »

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.
User avatar
norubal
Party member
Posts: 137
Joined: Tue Jan 15, 2013 5:55 am

Re: Tile collision example

Post by norubal »

nice work, better than my code :)
lieudusty
Prole
Posts: 14
Joined: Thu Feb 21, 2013 5:19 am

Re: Tile collision example

Post by lieudusty »

Are slopes implemented yet? I can't figure out how to make one.
User avatar
markgo
Party member
Posts: 190
Joined: Sat Jan 05, 2013 12:21 am
Location: USA

Re: Tile collision example

Post by markgo »

lieudusty wrote:Are slopes implemented yet? I can't figure out how to make one.
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.
Attachments
demo+slopes.love
(3.37 KiB) Downloaded 401 times
User avatar
markgo
Party member
Posts: 190
Joined: Sat Jan 05, 2013 12:21 am
Location: USA

Re: Tile collision example

Post by markgo »

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.
Attachments
demoV3.love
Arrows to move.
(4.41 KiB) Downloaded 577 times
Mekapix
Prole
Posts: 3
Joined: Tue Sep 23, 2014 10:07 am

Re: Tile collision example

Post by Mekapix »

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.
Mekapix
Prole
Posts: 3
Joined: Tue Sep 23, 2014 10:07 am

Re: Tile collision example

Post by Mekapix »

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!
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 220 guests