Help with tiles and collisions

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
PurplePartyGator
Prole
Posts: 1
Joined: Tue Oct 15, 2013 6:10 pm

Help with tiles and collisions

Post by PurplePartyGator »

Hello. I'm working on creating a platform game as a project for school and everything has been smooth sailing until I get to tile collision. To make my map I used Tiled and to load my map I used the advanced tiled loader library. I'm trying to make my player not be able to just go through the tiles as if nothing were there but instead have the tiles act something like the boundaries I have set for the windows. If anyone could explain to me how I would implement something like this into my game that would be great. here http://www.mediafire.com/download/n5u85 ... tform.love is my .love file.
User avatar
micha
Inner party member
Posts: 1083
Joined: Wed Sep 26, 2012 5:13 pm

Re: Help with tiles and collisions

Post by micha »

Welcome to our forum.

First of all, expect the collision to take some time, until you get it right. Collision is not easy.

The general approach is like this. In the update function you change the position of the player. After that you check if there is a collision (collision detection) and if so, then you resolve it by moving the player to a position, where there is no collision.

A tutorial that helped me a lot is this: Platform Game Programming Tutorial. The collision part is in part 4, but I suggest you read the whole tutorial.

Some thoughts are also on The guide to implementing 2D platformers.

The method that worked best for me, was to divide movement into x- and y- movement and to do collision that way as well. First move the player only in x-direction. If a collision occurs, then move him back along the x-direction, until the collision is resolved. Then repeat this procedure for the y-direction.
Post Reply

Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 5 guests