Simple, lightweight, general purpose collision detection

Showcase your libraries, tools and other projects that help your fellow love users.
User avatar
TechnoCat
Inner party member
Posts: 1611
Joined: Thu Jul 30, 2009 12:31 am
Location: Denver, CO
Contact:

Re: Simple, lightweight, general purpose collision detection

Post by TechnoCat »

I responded to a PM about using Noah's Ark to learn about sidescrolling and I thought my response could help the general public.
TechnoCat wrote: I'm glad you like my Noah's Ark game!

However, I strongly encourage you not to use any of Noah's Ark code and to merely look at it. I wrote that code and created all the graphics during a 48 hour gamejam. It is really messy and really hardcoded! Like you said, take out one thing and it all falls apart.

There are 4 paths to collision detection and resolution for sidescrollers that I will recommend.
  • Use Fizz (or similar, of which I am aware of no others)
    1. This library was written specifically to be a drop-in solution to making a sidescroller.
    2. Lightweight
    3. Very easy
    4. Might not have all functionality (It tries to be a single solution)
  • Use Hardon Collider (My personal favorite path)
    1. This library is written to purely be a collision detection library, not a collision resolution library. However, detection is the hard part.
    2. Lightweight
    3. A little bit of difficulty. (requires you read the HC API)
    4. Very robust (this library makes almost no assumptions)
  • Implement a versatile collision detection library (such as Metanet's)
    1. To do this you are going to need a really good understanding of Linear Algebra
    2. You'll still have to resolve collisions after you implement this.
  • Use Box2D
    1. Box2D is often considered unsuitable for sidescrollers. But, Kurosuke and some others get away with it.
    2. love.physics is actually Box2D
I hope this helps you get started.
User avatar
tentus
Inner party member
Posts: 1060
Joined: Sun Oct 31, 2010 7:56 pm
Location: Appalachia
Contact:

Re: Simple, lightweight, general purpose collision detection

Post by tentus »

TechnoCat wrote:I responded to a PM about using Noah's Ark to learn about sidescrolling and I thought my response could help the general public.
TechnoCat wrote: I'm glad you like my Noah's Ark game!

However, I strongly encourage you not to use any of Noah's Ark code and to merely look at it. I wrote that code and created all the graphics during a 48 hour gamejam. It is really messy and really hardcoded! Like you said, take out one thing and it all falls apart.

There are 4 paths to collision detection and resolution for sidescrollers that I will recommend.
  • Use Fizz (or similar, of which I am aware of no others)
    1. This library was written specifically to be a drop-in solution to making a sidescroller.
    2. Lightweight
    3. Very easy
    4. Might not have all functionality (It tries to be a single solution)
  • Use Hardon Collider (My personal favorite path)
    1. This library is written to purely be a collision detection library, not a collision resolution library. However, detection is the hard part.
    2. Lightweight
    3. A little bit of difficulty. (requires you read the HC API)
    4. Very robust (this library makes almost no assumptions)
  • Implement a versatile collision detection library (such as Metanet's)
    1. To do this you are going to need a really good understanding of Linear Algebra
    2. You'll still have to resolve collisions after you implement this.
  • Use Box2D
    1. Box2D is often considered unsuitable for sidescrollers. But, Kurosuke and some others get away with it.
    2. love.physics is actually Box2D
I hope this helps you get started.
A little tweaking and that would be a very helpful wiki entry, we see the topic brought up enough for it to be worth it IMHO. Also, thanks for mentioning Kurosuke!
Kurosuke needs beta testers
User avatar
lots_of_birds
Prole
Posts: 13
Joined: Sun Dec 11, 2011 12:09 pm

Re: Simple, lightweight, general purpose collision detection

Post by lots_of_birds »

Hi there,
I've followed the HC tutorial, and I've found several bugs on it.
Too bad it's not a wiki. I'm not sure where to contribute, so, I gess here is better than not doing it.

On the rebound part only: (on the whole picture the code is right on this part)

Code: Select all

ball.velocity.y = bx - py
should be instead:

Code: Select all

ball.velocity.y = by - py
---
In the function on collide, when introduced and on the whole picture, undefined variables are used instead of the right and left goals

This:

Code: Select all

 if other == goalLeft then
        ball.velocity = {x = 100, y = 0}
        ball:moveTo(400,300)
    elseif other == goalRight then
should be this:

Code: Select all

 if other == borderLeft then
        ball.velocity = {x = 100, y = 0}
        ball:moveTo(400,300)
    elseif other == borderRight then
----
----

By the way, I'm pretty impressed with the work done. Is there still work to be done ? Is there some kind of bug index ?
User avatar
lots_of_birds
Prole
Posts: 13
Joined: Sun Dec 11, 2011 12:09 pm

Re: Simple, lightweight, general purpose collision detection

Post by lots_of_birds »

I have a question about this library.

I can't figure why it print messages on the output of my program.

I've checked the source code, I've found the corresponding lines, but I still don't understand what it means.

The messages are "collide?" and "sat"

Anyone knows what I am doing wrong, or what does it means?
coffee
Party member
Posts: 1206
Joined: Wed Nov 02, 2011 9:07 pm

Re: Simple, lightweight, general purpose collision detection

Post by coffee »

One question please, I'm seeing a lot here in several posts talking about detection done with boxes, hardon collisions, minimal detection and so on but seems that in LOVE mask detection technique (with slower pixel full mask point to point detection or more faster selected pixel points detection) a bit forgot and unused around. There is any reason or inconveniences for using such techniques? Is an obsolete concept/technique?
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: Simple, lightweight, general purpose collision detection

Post by bartbes »

Mostly because you need to keep the ImageData of everything around, if you've got a single (or few) level images, it sure is an option. Come to think of it, you can probably all draw it to a FrameBuffer and go from there.
coffee
Party member
Posts: 1206
Joined: Wed Nov 02, 2011 9:07 pm

Re: Simple, lightweight, general purpose collision detection

Post by coffee »

bartbes wrote:Mostly because you need to keep the ImageData of everything around, if you've got a single (or few) level images, it sure is an option. Come to think of it, you can probably all draw it to a FrameBuffer and go from there.
Thank you bartbes, I have somewhere in an old pc a small game done in some Basic engine using Mask Collision. Perhaps after current project gonna try speedily convert it to LOVE.
User avatar
vrld
Party member
Posts: 917
Joined: Sun Apr 04, 2010 9:14 pm
Location: Germany
Contact:

Re: Simple, lightweight, general purpose collision detection

Post by vrld »

lots_of_birds wrote:The messages are "collide?" and "sat"
I must have checked in a "debug" version. Simply remove the prints in line 182 and 184 of shapes.lua.
SAT stands for Separating Axis Theorem and is what HC uses for fine collision detecion.

The messages will be removed in the next version of HC (which will also use Class Commons for good measure).
I have come here to chew bubblegum and kick ass... and I'm all out of bubblegum.

hump | HC | SUIT | moonshine
User avatar
lots_of_birds
Prole
Posts: 13
Joined: Sun Dec 11, 2011 12:09 pm

Re: Simple, lightweight, general purpose collision detection

Post by lots_of_birds »

I feel relieved, thanks !
User avatar
vrld
Party member
Posts: 917
Joined: Sun Apr 04, 2010 9:14 pm
Location: Germany
Contact:

Re: Simple, lightweight, general purpose collision detection

Post by vrld »

HardonCollider Update!
  • Fixed polygon triangulation bug.
  • Added Spatialhash:draw()
  • Use class-commons for all the things
Usage of class commons is optional. If you don't use it, HC will work regardless. If you do, do it like so:

Code: Select all

class_commons = true
require 'slither'
Collider = require 'hardoncollider'
-- rest as usual
Attachments
demo.love
(17.22 KiB) Downloaded 200 times
I have come here to chew bubblegum and kick ass... and I'm all out of bubblegum.

hump | HC | SUIT | moonshine
Post Reply

Who is online

Users browsing this forum: No registered users and 58 guests