开发者

More Accurate Tile Based Collision

First off, the player will be controlling a circular object. Im trying to do collision in a tile based game. One of my problems is not all the ti开发者_Go百科les are square. They are all sorts of irregular shapes. The way I was thinking of handling this was by doing 2 checks; 1) check if the player is in range of a hittable tile 2) check (somehow) if they actually came in contact with the tile

How would I do this? Or Is there a better way? I'm using C#/XNA (probably not important)


There are several ways to handle this. Personally I would keep track of all of the collideable objects in a list. If there will be many objects (more then say 200) you could keep several lists. Each list would represent a quarter or eighth of the screen. On each update you can run through the lists and check for objects colliding (Tiles overlapping). If the tiles overlap then you would check for Pixel Perfect Collisions.


You could first check for rectangular collision and if there is a collision check for per-pixel collision.

These two links are really great and are pretty good introductions to basic collision detection with XNA.


I would recommend using a physics engine. You can find tutorials and documentation for each one on their websites or by a google search. These are some XNA physics engines:

  1. Farseer Physics
  2. JigLibX
  3. PhisiXNA (I just found this in a google search and can't vouch for it, but the other two are very well used in the XNA community)


I am planning to create the following solution for my next project:

  1. Each GameObject in my game will have a CollisionRectangle field.
  2. Create a CompositeRectangle object that will be comprised of multiple rectangles. The upside of this is that (in my case at least) it can be created using some Content Pipeline processor at build time, getting my CollisionRectangle for free, and checking for it as usual by calling .Collides(...)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜