Jump to content

  • Log In with Google      Sign In   
  • Create Account


Collision detection


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
7 replies to this topic

#1 vaironl   Members   -  Reputation: 128

Like
0Likes
Like

Posted 11 June 2012 - 06:25 PM

Hello i have a question about collision.

I was seeing the following video, , 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?

Sponsor:

#2 thok   Members   -  Reputation: 684

Like
0Likes
Like

Posted 12 June 2012 - 03:01 AM

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?


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.

#3 vaironl   Members   -  Reputation: 128

Like
0Likes
Like

Posted 12 June 2012 - 07:19 AM


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?


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.


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.

#4 thok   Members   -  Reputation: 684

Like
1Likes
Like

Posted 12 June 2012 - 08:56 AM



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?


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.


Thanks for replying thok and sorry if my question is not very understandable ( English is my second language Posted Image )
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.


No worries, English is my _only_ language (apart from a smattering of offensive phrases in Swiss German). Posted Image

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.

#5 Cornstalks   Crossbones+   -  Reputation: 6974

Like
1Likes
Like

Posted 12 June 2012 - 09:40 AM

Here are some of my favorite links on collision detection:

N Tutorial A (covers the Separating Axis Theorem, which is one way to implement collision detection)
N Tutorial B (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))

Speculative Contacts (a different way to do collision detection)
Physics engines for dummies

Edited by Cornstalks, 12 June 2012 - 09:40 AM.

[ I was ninja'd 71 times before I stopped counting a long time ago ] [ f.k.a. MikeTacular ] [ My Blog ] [ SWFer: Gaplessly looped MP3s in your Flash games ]

#6 vaironl   Members   -  Reputation: 128

Like
0Likes
Like

Posted 12 June 2012 - 10:22 AM

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?

#7 thok   Members   -  Reputation: 684

Like
1Likes
Like

Posted 12 June 2012 - 10:59 AM

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?


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.

#8 vaironl   Members   -  Reputation: 128

Like
0Likes
Like

Posted 17 June 2012 - 07:47 PM


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?


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.


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.






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS