Jump to content
  • Advertisement
Sign in to follow this  

Suggestions for collision detection ...

This topic is 4127 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi all, I just need a suggestion as to how to implement collision detection in my game. The game is top-down ( like cannon fodder ) and has tiles which are drawn half-grass and half-forest. Enter stage left: reason for uncertainty - At the minute the map is stored in a multi-integer array mTileMap[x][y][l], and all of the characters in the game are floats. The [x] and [y] are obviously the tile positions, and the [l] is of size int 3, and is used for the tile information. At first I just wanted to use [l] to store an integer value for passable or not, but the tiles are too big to allow for this, so I need a more precise way of declaring ONLY PARTS of tiles passable. Take an example of a tile being half forest (impassable) and half grass (passable), so I would have to declare this half-half. and thoughts / ideas would be greatly appreciated ... -Thanks [Edited by - LintfordPickle on January 26, 2007 3:29:44 AM]

Share this post


Link to post
Share on other sites
Advertisement
You could simply make an integer listing what type of landscape is in the spot attempting to be moved to; and for each type of player object have an array of booleans if they can move on the different types? then do a quick check?


if(object.canMove[type])
goToMoveMethod();//?

Share this post


Link to post
Share on other sites
Hi JakeRad,

That was my problem, because the tiles I have are larger than the units, 1 integer to represent a whole tile wouldn't be enough. e.g.

A tile of size 64x64 pixels:
___________
| . . . . . . . .| = water
|. . . . . . . .|
|-----------|
|/////////////| = grass
|__________|

On this tile, the lower half should be passable, and the top half not, and I don't know the best way to represent a half tile.

I think at the minute, it might be better to use a linked list of rectangles, all of which I can't pass, and just check the units movement, but I want to do a map editor in the future and don't know if this will be do-able.


Thanks for your reply

Share this post


Link to post
Share on other sites
well, make the array have four ints, representing the tile. One to represent each corner or something. If your going to make a map editor it would be much more simple to just identify the type of landscape, rather then splitting the leval up as passable or not. Then have the checks during movement.

Just an oppinion.

Share this post


Link to post
Share on other sites
Hi,

I'll take a look at the 2-tiered method, but for the moment maybe you could tell me ( in advance of me finishing it ) whether the following would work, I have the int array mTileMap[x][y][l].

X, Y = Position.

L = Layer and the values are 1 through 20, representing the following :

1 = texture to display for the current co-ord.

2 = walk / swim ( 1 / 0 )

3 - 19 = Each tile [X][Y] will be divided into 16 smaller squares, numbered 3 - 19, and the integer value will represent the 'passable-ness' of each square. Then all I have to do is check the movement of the player based on this last integer. ( 1 / 0 )

Do you think this will work, or are there some problems that I'm not taking into consideration? ( like int mTileMap[100][100][20] would be too big etc. etc. )

Thanks for all your replies

Share this post


Link to post
Share on other sites
I personally consider breaking up a single grid coordinate into several pieces very time consuming. It is doing many checks each frame.

I would just set up polygon collision lines, and check only the lines that could possibly be within the player's sprite.

To check whether or not the player hits water or not is another question. You could use that line to determine which half the player is crossing the most of and do it that way.

Just a thought.

Share this post


Link to post
Share on other sites
Wouldn't it be better for your tilemap array to contain an array of tile objects? That way one of the attributes can be 'walkability' and hold an actual
value (e.g. 5 for grass, 1 for swamp etc). Your way will probably work but you're going to end up stuck for something else (e.g. when destroyed what tile should be displayed or this tile contains a trap or whatever).

Share this post


Link to post
Share on other sites
This may be a noob suggestion or question - whichever.
Given the above setup - why not define your tiles yourself, with say 0-99 as walkable (grass, sand, beach, etc.) and 100 and up being impassable.
This would effectively give you 99 tiles that are passable and many more that would be impassable.
A movement/collision check would be something like if blah < 100 then passable else impassable.
Just a noob trying to make since of this stuff.

Share this post


Link to post
Share on other sites
I would also use tonyg's idea...

For every tile-object you could implement a check Method to see if the "next step" is possible.

tile[j].canMove(x, y);

The objects could save if the tile is blocked vertical or horizontal

Horizontal:
____________
|. . . . . .| = water
|. . . . . .|
|-----------|
|///////////| = grass
|___________|

Vertical:
____________
|/ / /|. . .|
|/ / /|. . .|
|/ / /|. . .|
|/ / /|. . .|
|/_/_/|._._.|


So if you try to access tile 2,3 on the pixel 5,5 (horizontal blocked)you will get a false from the method, because the tileObject is blocked...

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!