2d tile map collision

Started by
0 comments, last by Captain P 13 years, 10 months ago
What is the best way for collision detection? ( 2d collision in opengl es for iphone with Objective C)

I can do a ray intersection on every tile map which my map is pretty big and may contain several hundred tiles.

Although I guess I could do a for loop for only visible tiles and calculate whether the players shape intersects any visible tile.

Is that the best way to do it or is there better prescribed ways to determine if a player runs over a tile that has illegal movement?

just curious.
Nick
Advertisement
What kinds of collision checks do you need? You've got a 2D grid, but what kind of shapes are you working with? Do you only need to check for collisions between a player and the world, or also against other game objects? Do you need to determine if one game object can 'see' another game object?


Either way, if you've got a rectangular shape for your player, and tiles are either completely solid or completely open, then it's fairly easy to check if the player collides with solid tiles. Based on it's position and dimension, and the tile size, you can calculate which rows and collumns it (partially) overlaps. Then check if any of those tiles are solid.

You'll probably want to know a bit more than that, though, such as how far the player intersects with any of those tiles. You could then 'push out' the player accordingly, or partially revert his movement.
Create-ivity - a game development blog Mouseover for more information.

This topic is closed to new replies.

Advertisement