Old school 2D plataformer controller?

Hi!,

After playing for a while with built-in character controller, I have decided to roll my own or check one that have made someone. The problems with character controller for 2D are more a matter of taste than real problems. I don’t like my sprites to “climb” walls or platforms because the collider is a rounded shape (capsule, sphere, etc…) for example.

So, has anybody created one? I have spent some time today playing with raycasts, but there are a lot of problems with shapes smaller than the hero itself, etc… (I coudl get rid of this ones wisely creating my levels). I Have been thinking about using sweeptest but I think it is not an option because of performace (Raycast could not be the best method either).

I would like to make it as lightweight as possible (I think everyone seeks this :)). Anybody could suggest where to start with this using unity? Better forget Raycasts and use collision system? Better to use just triggers?.

Thanks in advance,
HexDump.

Hi!,

Sorry to up the thread so soon, but just wanted to explain my findings/thoughts. I have been reading a lot on the subject but I can’t find a suitable solution. I have been trying about using colliders and kinematic rigidbody and try to adjust things when event OnTriggerEnter is produced. The result without using any raycast is that player (kinematic body) produce a jerky movement. So I have two options now:

  1. Building some kind of quadtree where I store references to colliders. Then I test collisions myself (like we have done since 80’s, checking if colliders overlap). This could work, but It is a bit of work, and I’m really surprised do not provide any mechanism to make things easier.

  2. Use Raycast, every test will be done in the axis we are moving, I mean, max raycast per check will be 4 ray casts,2 in x and 2 in y (I can’t have bits of floor smaller than the player). If I have to do this for every alive enemy it could be really overkill I think. I will have about 5 or 6 enemies alive that will be around 24 raycasts per frame.

What do you think? Any one has tried to go first way?. I’m a bit lost at the moment :/.

Thanks in advance,
HexDump.

Short answer, forget about unity and pickup other solutions, long answer in your private inbox

For a 2D gameplay, there are other options than Unity’s Colliders. You can handle collision detection on your own without the need for complex 3D raycasting or colliders interpenetration. For ages now collisions in 2D have been handled with simple shape to shape distance tests (point to circle, circle to circle, box to box, point to box, etc…). These require very lightweight computations and involves more complex optimizations only if you have to test collisions of many things against many other things. In these cases simple implementations of quad tree or other similar solutions is really not that complex and have been done many times by others for plateform like Flash. There are quite a few available solutions easily portable from actionscript to C# or javascript out there.

Collisions with ground for 2D plateform games are classically not handled with object to object tests. You should have a grid representation of your level with a walkable / not walkable property for each square of the grid. Collision is then a simple matter of knowing on which square your character is standing or where he’s trying to go.

Unity3D is has suited to this kind of things as pretty much any other solution. Some other softwares will have these grid representations already implemented but this is really really not that complex to do from scratch.

Hi!,

Eskema, this is what I was thinking about. But I Really like unity workflow and I think I will stick to it by now :).

Krobill: I forgot to say that my floors are not made of tiles in the ussual sense. They are overlaped planes with different sizes. I have done this a lot of times with my own engine, just wanted to know if unity provides any better inhouse solution for this. Perhaps a QuadTree+Colliders to flag collisions (I would just use lines) is what I need.

Thanks in advance,
HexDump.