Hello Guest

Author Topic: Tile base platformer collision detection?  (Read 6572 times)

Neeko

  • 2D Toolkit
  • Jr. Member
  • *
  • Posts: 59
    • View Profile
    • Overdeveloped
Tile base platformer collision detection?
« on: February 16, 2014, 02:01:04 pm »
A popular method for doing platformer collision detection in Unity seems to be by raycasting, however whenever I try this, I constantly run into bugs that result in the player falling through collision layers.

I'm at wit's end trying to resolve these bugs, thus since I'm using tk2d's tile map, I'm considering using a more "traditional" method of checking the player's position and desired move amount against nearby tiles, determining what type they are (are they passable, impassable, etc) and altering the player's final movement as appropriate.

I don't see people (at all) using this method, and considering that this method has a long history of being battle proven, I'm curious as why not? Is there some "Unity" road block I don't see that would make this not work? Has anyone here attempted something similar?

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Tile base platformer collision detection?
« Reply #1 on: February 16, 2014, 10:50:41 pm »
I've done something similar in the past, and if I were making a robust platformer with tight controls I wouldn't bother using physx or box2d either. Its much more efficient to collide that way, especially if your world is built out of boxes. Not just that but its much easier to make it really really robust. The only annoying thing is floating point, but even that isn't insurmountable.

Neeko

  • 2D Toolkit
  • Jr. Member
  • *
  • Posts: 59
    • View Profile
    • Overdeveloped
Re: Tile base platformer collision detection?
« Reply #2 on: February 17, 2014, 09:36:39 pm »
Agreed, I've found it nearly impossible to get the feel right when using Box2D. I am currently handling all acceleration and movement manually (most, if not all, objects are kinematic), it's the just collision detection that's been throwing me off. It's good to hear someone else was able to successfully achieve a tile-check based system in Unity.

Jellybit

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: Tile base platformer collision detection?
« Reply #3 on: June 10, 2014, 12:47:52 am »
I can't tell you how much I agree with this. I've been trying to solve this problem for months. I wrote some AABB collision, but I'm having a hard time dealing with tilemaps in an efficient way.

der_r

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: Tile base platformer collision detection?
« Reply #4 on: June 10, 2014, 10:23:48 am »
I'm currently working on a 2D platformer using 2dtk (Shadow of the Council in the showcase section). Right now I'm using my own basic physics component. What about using Physics2D.OverlapArea(All) to detect collisions? Has anyone else tried it? Is it efficient?

I'm using OverlapArea as well as raycasting right now and haven't had any problems with it, but my prototype is still pretty barebones.