Tile-Based Games - AABB

Started by
4 comments, last by SeanMiddleditch 9 years, 8 months ago

(Sorry for my weird English, I'm a french man)

Hello,

I read "Tile-Based Games FAQ version 1.2" and I still have questions.

Does each base tile have its own AABB ? Or AABB is the size of tile ?
If each tile have its own AABB how do I implement this ?


public class Tile 
{
	public static final int EMPTY = 0;
	public static final int BLOCK = 1;
	public static final int SLOPE = 2;
	
	// Type of block
	private int type;
	
	// AABB and position
	private int width;
	private int height;
	private float x;
	private float y;

	// ...
}

Like this ?

Advertisement

Well, do you need an AABB for each tile? In most of the cases you can derive the AABB from the position and width / height values.

Are there cases where the tile content might go over the tile border?

Question, why your width and height are defined as int?

Well, do you need an AABB for each tile? In most of the cases you can derive the AABB from the position and width / height values.


I look other tile-based game for learn and in Rogue Legacy I guess the AABB aren't in same size. And I want to know how to do this.

gffgfg10.png

Player can walk on the library and walk on ground.

Does it multi-layer ? Or different AABB ?

I'd say that the objects such as the table and the book shelf are separate objects and aren't part of the tile engine ie. they are drawn on top of the back ground - with their own AABB.

For the book shelf collision, I think that it is pretty simple - maybe just a horizontal plane (at the top of it) which allows the character to traverse it when moving upwards but blocks the movement of the character when it is moving downwards (and the old position isn't intersecting the line). This way the character can also walk in front of the book shelf.

Same kind of collision handling should work for the ground, the ramp and vertical walls, ie. a single plane defining on which side of it the character should stay.

So, AABB and the collision detection / handling aren't same thing. Although for certain cases (such as the character) the bound may be used for the collision detection. The game in the screenshot may be slightly more complicated than just a simple tile engine.

Cheers!

If you have a big, rectangular cluster of tiles, instead of each having their own bounding-box for collision detection you can have a single large box encapsulating everything.
There is no practical difference for the player, and you save a lot of tests with that.

So a level could have a combination of varied large collider shapes that try to encompass as many tiles as possible.

Another approach can be completely tile based, as discussed in this article:
http://www.gamedev.net/page/resources/_/technical/game-programming/the-guide-to-implementing-2d-platformers-r2936

I look other tile-based game for learn and in Rogue Legacy I guess the AABB aren't in same size. And I want to know how to do this.


The game is mostly tile based with fixed AABBs. You can support a fixed set of different shapes of tiles, e.g. a square tile, a left-facing 45 degree slope, a right-facing slope, etc. Then instead of storing an entire AABB in each tile you need only store a little enum that defines the basic shape of the tile, with the specific collision values calculated based on the tile's position on its shape. See the classic N+ collision tutorials.

You probably don't even want AABBs for your tiles, as this approach means you'll have "edges" between two adjacent tiles that your character may sometimes get snagged or stuck on. You will want a more specialized collision system for tiles that treats a floor as a single continuous flat surface rather than a bunch of separate boxes. There are many articles on this approach; I believe the N+ one above deals with it but it's been a while since I've read it. The guide to implementing 2D platformers also covers this and the next topic.

Note of course that for sloped tiles or the like you're not using AABBs for the actual collision (you might use them for broadphase/midphase still).

For objects that aren't aligned to tiles, you need to support both tile collision detection and arbitrary AABB collision detection.

Player can walk on the library and walk on ground.
Does it multi-layer ? Or different AABB ?


The trick is relatively simple. For certain tiles (or objects, for non-tile-aligned set pieces) there are flags indicating that collision should be ignored based on the direction the player collides with the object. There are a few special rules you apply to objects marked with this flag:

1) If the player collides from the left or right or bottom, ignore the collision.

2) If the player is already overlapping the object then stop performing collision checks until they separate (this is an important but often overlooked detail to avoid some weird bugs when jumping while standing in front of such an object).

3) If the player collides form the top then stop the movement like a normal solid tile collision, unless the player is holding the "fall through" button (sometimes down or such; some games don't allow this at all).

These rules allow the player to jump on the tile/object but otherwise walk through it normally. You can do the same for sides of tiles to make one-way force fields or the like, too.

Sean Middleditch – Game Systems Engineer – Join my team!

This topic is closed to new replies.

Advertisement