Sign in to follow this  
vaironl

Collision detection

Recommended Posts

Hello i have a question about collision.

I was seeing the following video, http://www.youtube.com/watch?v=RZaKd5BG0mI&feature=channel&list=UL, and I asked myself "How is the collision being made with multiple walls, in different places"?

When I usually do collision detection it is a square and the boundaries of the frame.

Now I would like to make a level and the way I did this was with a picture, are there other ways?
If so what are those?

Share this post


Link to post
Share on other sites
[quote name='vaironl' timestamp='1339460744' post='4948342']

When I usually do collision detection it is a square and the boundaries of the frame.

Now I would like to make a level and the way I did this was with a picture, are there other ways?
If so what are those?
[/quote]

Not sure if I understand your question exactly. Are you asking, "how do I detect collisions between the game character and the walls?" If so, please clarify your question.

There are many ways construct a level. For a simple platform game, a grid of tiles will suffice.

We can help you better if you can provide more specifics.

Share this post


Link to post
Share on other sites
[quote name='thok' timestamp='1339491661' post='4948430']
[quote name='vaironl' timestamp='1339460744' post='4948342']
When I usually do collision detection it is a square and the boundaries of the frame.

Now I would like to make a level and the way I did this was with a picture, are there other ways?
If so what are those?
[/quote]

Not sure if I understand your question exactly. Are you asking, "how do I detect collisions between the game character and the walls?" If so, please clarify your question.

There are many ways construct a level. For a simple platform game, a grid of tiles will suffice.

We can help you better if you can provide more specifics.
[/quote]

Thanks for replying thok and sorry if my question is not very understandable ( English is my second language :( )
To my believe,yes, it is detection of character and walls or blocks. I sometimes draw images with lines and I really don't understand how could make a collision detection system.

Share this post


Link to post
Share on other sites
[quote name='vaironl' timestamp='1339507191' post='4948471']
[quote name='thok' timestamp='1339491661' post='4948430']
[quote name='vaironl' timestamp='1339460744' post='4948342']
When I usually do collision detection it is a square and the boundaries of the frame.

Now I would like to make a level and the way I did this was with a picture, are there other ways?
If so what are those?
[/quote]

Not sure if I understand your question exactly. Are you asking, "how do I detect collisions between the game character and the walls?" If so, please clarify your question.

There are many ways construct a level. For a simple platform game, a grid of tiles will suffice.

We can help you better if you can provide more specifics.
[/quote]

Thanks for replying thok and sorry if my question is not very understandable ( English is my second language [img]http://public.gamedev.net//public/style_emoticons/default/sad.png[/img] )
To my believe,yes, it is detection of character and walls or blocks. I sometimes draw images with lines and I really don't understand how could make a collision detection system.
[/quote]

No worries, English is my _only_ language (apart from a smattering of offensive phrases in Swiss German). [img]http://public.gamedev.net//public/style_emoticons/default/biggrin.png[/img]

So, what do you have so far? I'm going to assume that you're creating a 2D platform game. That's what I'm working on right now, so I can share with you what I did. I'm new to game development also, so ohers with more experience are welcome to criticize my methods. So far, it seems to work pretty well. (Note: There are many chances for optimization in this method, but it's simple and works in concept.)

Here is something fairly simple you can try:
- You'll need an update/render loop. I'm assuming you already have this.
- Define something to contain your level data. At most basic level, that means a 2-dimensional array of integers (for example).
- Define a tile size. I use 48x48 pixel tiles.
- Each element in your 2d array represents a tile. Use the value 0 for empty space and 1 for solid blocks (for walls, floors, and celings).
- Each tile has a rectangular representation. If you treat your player character as a rectangle as well (x, y, width, and height), collision _detection_ is rather simple. This article may help: http://www.gamedev.net/page/resources/_/technical/game-programming/collision-detection-r735
- When you move your character during the update, move one axis at a time. Once you've move, loop through all of your tiles; if a tile is solid, check for collision.
- 'Collision' really means 'overlap'. That means your collision has it's own shape. In the case of rectangle-to-rectangle collisions, your collision shape will also be a rectangle.
- When you encounter a collision on a given axis, you need to push the player out of the collision. The size of the collision will tell you how far you need to move to get out of the collision. The current direction of the player will tell you which way to move to respond to the collision.

Final note: Don't worry so much right now about _drawing_ things; worry first about representing the data (in this case, data = tile data). Once you have your data defined (location and size of tiles), then you can render simple graphical representations, such as colored rectangles. Later, you can add images, and so on.

I hope that helps. If not, maybe you can describe what you have so far and we can help you build on that.

Share this post


Link to post
Share on other sites
Here are some of my favorite links on collision detection:

[url="http://www.metanetsoftware.com/technique/tutorialA.html"]N Tutorial A[/url] (covers the Separating Axis Theorem, which is one way to implement collision detection)
[url="http://www.metanetsoftware.com/technique/tutorialB.html"]N Tutorial B[/url] (covers broad-phase collision detection, (i.e. you do this first to rule out things you know aren't colliding, then you use tutorial A for objects that are colliding))

[url="http://www.wildbunny.co.uk/blog/2011/03/25/speculative-contacts-an-continuous-collision-engine-approach-part-1/"]Speculative Contacts[/url] (a different way to do collision detection)
[url="http://www.wildbunny.co.uk/blog/2011/04/06/physics-engines-for-dummies/"]Physics engines for dummies[/url] Edited by Cornstalks

Share this post


Link to post
Share on other sites
When I usually do collision detection it is a square and the boundaries of the frame.......

Thanks.
I'M currently doing a 2D Game using Java . I'm randomly generating red blocks which are 32 x 32.
Now you say use a 2 dimensional array.
I understand how to make them but if my screen is 800 x 600 does that mean I would check every 32x32 area for a block?

Share this post


Link to post
Share on other sites
[quote name='vaironl' timestamp='1339518134' post='4948537']
When I usually do collision detection it is a square and the boundaries of the frame.......

Thanks.
I'M currently doing a 2D Game using Java . I'm randomly generating red blocks which are 32 x 32.
Now you say use a 2 dimensional array.
I understand how to make them but if my screen is 800 x 600 does that mean I would check every 32x32 area for a block?
[/quote]

Screen size != level size. I would model them as separate entities.

Your display is 800x600 pixels. Your level can be much bigger than that (if you want to be able to scroll around the level as your character runs around).

Your level should be of any size. It will be some number of tiles high and some number of tiles wide. You can model this as a Level object, which can contain the 2-dimensional tile array.

Share this post


Link to post
Share on other sites
[quote name='thok' timestamp='1339520360' post='4948549']
[quote name='vaironl' timestamp='1339518134' post='4948537']
When I usually do collision detection it is a square and the boundaries of the frame.......

Thanks.
I'M currently doing a 2D Game using Java . I'm randomly generating red blocks which are 32 x 32.
Now you say use a 2 dimensional array.
I understand how to make them but if my screen is 800 x 600 does that mean I would check every 32x32 area for a block?
[/quote]

Screen size != level size. I would model them as separate entities.

Your display is 800x600 pixels. Your level can be much bigger than that (if you want to be able to scroll around the level as your character runs around).

Your level should be of any size. It will be some number of tiles high and some number of tiles wide. You can model this as a Level object, which can contain the 2-dimensional tile array.
[/quote]

Your help was not a waste, :).
I'm learning how to use the array to check for collision ( and it's actually coming out better than before)

I still don't know how to make the level bigger than the screen size, but I've notice that if I try to figure things out I do (this crappy simple game is an example)

I will try to update the process through videos frequently, once again thanks.

[url="http://www.youtube.com/watch?v=HytKxenTn0k"]http://www.youtube.com/watch?v=HytKxenTn0k[/url]

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this