Newbie Collision Detection question

General discussion about LÖVE, Lua, game development, puns, and unicorns.
Post Reply
CO
Prole
Posts: 3
Joined: Fri Jan 24, 2014 2:04 am

Newbie Collision Detection question

Post by CO »

Hi,

I read up on all the collision detection questions that have been previously posted. None of them addresses my issue, and a lot of the code samples supplied to solve issues are more complicated than I understand.
I am working on an a simple 2D shooter game, set up sort of Mario style. My character has an issue that I cannot resolve, and I was hoping one of you might have a tidbit stuck somewhere in those brilliant heads of yours that could help me out.

The basic issue is collision detection. Everything in my game works except this one thing, and I cannot figure it out. I think I need an function to override the player/tiles collision, but everything I try does not work. The player is bleeding into the next tile and then auto-jumping on top of it, instead of stopping because the tile is blocking its path.
image001.jpg
image001.jpg (16.5 KiB) Viewed 2055 times
The above image shows two tiles, and a player. The player is moving in the direction of the arrow. When the back side of the players personal space reaches the front of tile 1, the player jumps up on to tile two automatically.

Or......
image002.jpg
image002.jpg (15.91 KiB) Viewed 2055 times
If there is no tile two, the player will bleed ¾ into tile 1 then jump up on to tile 1.

In both cases, the player should dead STOP at before passing tile 1 and be unable to proceed unless the jump button is tapped. Can you help me with a simple function that will resolve this issue?

Thank you.
CO
User avatar
micha
Inner party member
Posts: 1083
Joined: Wed Sep 26, 2012 5:13 pm

Re: Newbie Collision Detection question

Post by micha »

Are you using a library for the collision detection or did you code it yourself? Best would be, if you could post a minimal example in a .love file, so we can reproduce it ourselves.
User avatar
Plu
Inner party member
Posts: 722
Joined: Fri Mar 15, 2013 9:36 pm

Re: Newbie Collision Detection question

Post by Plu »

If your player bleeds halfway into your tiles, are you sure you are doing the coordinates correctly? Images are drawn on their topleft corner, but by default most collision libraries and functions work from the center. This can cause things to register collisions incorrectly because the collision library thinks the object is in a different location than it really is.
CO
Prole
Posts: 3
Joined: Fri Jan 24, 2014 2:04 am

Re: Newbie Collision Detection question

Post by CO »

Actually Plu, you may be on to something. Let me comb over my code to see. I have been blaming my character settings, but perhaps it is my tile settings that are the culprit. Thanks for the idea.
CO
Prole
Posts: 3
Joined: Fri Jan 24, 2014 2:04 am

Re: Newbie Collision Detection question

Post by CO »

Micha, I used some starter code and modified it to fit my situation.
User avatar
JovialFeline
Prole
Posts: 28
Joined: Wed Jan 08, 2014 2:32 pm

Re: Newbie Collision Detection question

Post by JovialFeline »

I think the first problem is largely tied to your second. In your first problem, Tile #1 is resolving its collision with the player by moving them to its right and then tile #2 resolves its collision by moving the player upward.

Something about your collision detection is off. Your tiles are reading the player's position differently than you're expecting (or perhaps vice versa). Problem #2 hints the tile is seeing the player inside its bounds when he tries to walk off. Once you can get the player to stop "bleeding" into tiles, the only thing you should have to worry about is resolving a player landing from a jump onto the overlap between two tiles. You might see a recurrence of problem #1 in that case.

Any chance we could see the collision code? :)
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 1 guest