Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Best library or method for collision  (Read 2344 times)

0 Members and 1 Guest are viewing this topic.

GroundZero

  • Jr. Member
  • **
  • Posts: 69
    • View Profile
Best library or method for collision
« on: September 04, 2011, 10:22:50 pm »
Heya, im making a 2D RPG game somewhat like Maplestory.
Only thing is that my current collision system aint doing what I want it to do. It works but the accuracy aint perfect. Like the sample here:


Code: [Select]
                       _______________
                        |               |
                       -                |
                      |                 |
                      |                 |
                      |                 |
--------------------                    -----------------------


You see a platform... only thing is that the top aint as width as the lower section of the platform, and thus the character would be walking in the air for a couple of pixels instead of falling off.

So I need a better collision system and -or library which is easy to use.

Does anyone have any suggestions or a sample code working in SFML 2.0 ? the one from wiki aint working (i think its 1.6 version?).

best regards

thePyro_13

  • Full Member
  • ***
  • Posts: 156
    • View Profile
Re: Best library or method for collision
« Reply #1 on: September 05, 2011, 04:19:12 am »
You can make the object out of multiple smaller objects like this:
Code: [Select]
                        _______________
                        |  Object 1     |
                       -----------------|
                      |                 |
                      |   Object 2      |
                      |                 |
--------------------                    -----------------------
And then check for collision against both of them, otherwise you have to starting looking into "Pixel Perfect Collision". Which is much slower, but more accurate.

Haikarainen

  • Guest
Re: Best library or method for collision
« Reply #2 on: September 05, 2011, 08:59:11 am »
Quote from: "thePyro_13"
otherwise you have to starting looking into "Pixel Perfect Collision". Which is much slower, but more accurate.


Pixel perfect collision isn't really that slow if you do it right, currently for my platformer, im using a very unoptimal(slow) method to achieve it, and i still get maxfps without drops(1000).

If you want pixelperfect; Create a rect for your player, and generate collisionmaps for each tile you load(2d-vector of bool's would be something), then check if you playerrect intersects with your tilerects, if they do, check if any pixel collides between the playerrect and the tile-collisionmap, based off the intersected intersection that sf::Rect::Intersects returns

P@u1

  • Jr. Member
  • **
  • Posts: 83
    • View Profile
Best library or method for collision
« Reply #3 on: September 05, 2011, 10:52:32 am »
Maybe Box2D can help you.
It works well for me.

GroundZero

  • Jr. Member
  • **
  • Posts: 69
    • View Profile
Best library or method for collision
« Reply #4 on: September 05, 2011, 10:57:45 am »
thanks for your replies guys, I will look into this :D

P.S. any tutorials on Collision with Box2D ?

 

anything