• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
BlinksTale

Simultaneous Multiple Object Collision Detection?

4 posts in this topic

Not prefixing because I want pseudocode rather than the C++ I'm working in. Also not looking for a library to import, as I'm trying to learn engine building technique. It's me, C++ and OpenGL/GLU/GLUT here, nothing else.

Collision detection has always been a big issue because of how expensive it is, I've heard. That I'm not worried about, a skim of the N+ tutorials has shown me that a grid system will work nicely for that. My problem is figuring out how to bounce off objects/kill overlap by applying halved inverse differences to three objects instead of two. My code is as follows:

[CODE]
for (a = 0 through maxPlayers) {
for (b = a through maxPlayers) {
if (a.collides(b)) {
bounceOffEachother(a,b);
}
}
}
[/CODE]

...where bounceOffEachother will take the difference between them, find the axis of least resistance, and push them away from each other on that dimension to create a slide or push effect. Everything is cube shaped, so this works out well.

So, for trying to fix this, I wanted to get all collisions, then apply all the bounces...


[CODE]
for (a = 0 through maxPlayers) {
Player collidedWith[maxPlayers];
int collisionSlot = 0;

for (b = a through maxPlayers) {
if (a.collides(b)) {
if (collisionSlot < maxPlayers) {
collidedWith[collisionSlot] = b;
collisionSlot++;
}
}
}

for (c = 0 through collisionSlot) {
bounceOffEachother(a,c)
}

}
[/CODE]

And yes yes it should be collidedWith[c] and I should be using playersPlaying[a] or something but this is pseudocode so I'm only doing what I have to for you to understand what I'm talking about. :P

So, my problem is, this technique still isn't working. I'll have my one dimensional bounces only apply to one collision still. Really, I'm not just using this for players, but also for walls, so if you hit two walls at once, only one of them has their collision create a bounce... meaning a row of walls doesn't work. So, any suggestions? I like having a two element bounceOffEachother function, but is that just not feasible for what I want to do?

Thanks guys!
0

Share this post


Link to post
Share on other sites
Have you debugged this to see if when you hit two walls there are really two collisions in your collidedWith array? Because it might visually look it did, but it is very hard to actually to collide with two walls at once. You might be actually a fraction of a millimeter off of one when you are colliding with the other. If this is happening, what you should do is accumulate collisions over multiple iterations and only then apply the collision response. So you don't react immediately upon collision, you wait for a few iterations and accumulate all collisions on a certain object before bouncing. Hope this helps.
1

Share this post


Link to post
Share on other sites
It does! At the least it will cut down my processing power issue with collision detection if I only check once every three cycles, and for some reason I wasn't thinking of that.

I've been playing with this more and it appears to be tied to which order my collisions are happening in - if I am moving across the tops of these blocks from the first ones checked towards the last ones checked, I don't fall, but the opposite direction commonly causes issues in bouncing/displacing. It also only happens when I have three cubes in a row, and I always fall in the middle one.

My best guess at this point is that I'm applying a displacement incorrectly and it's trying to bounce off the wrong block the wrong way at the wrong time. Read: I think I might just need more data. :P So I'm going to go hunting for it! Thanks again!
0

Share this post


Link to post
Share on other sites
Another thing is, usually physics simulations use another cycle counter to say so. If you make your simulation to run in your main game loop, you will be frame-rate dependent. Your simulation will run faster or slower depending on the frame rate, and if the frame rate drops you might see objects go through each other. What you want to do in this case is have a fixed timestep on which you run physics simulation that runs completely separate from the main loop to ensure simulation consistency.

Cheers!
1

Share this post


Link to post
Share on other sites
You're currently using an O(N^2) method for collision detection. This is fine when you don't have many moving objects in the world, but the amount of processing power required increases exponentially as you add more objects in. CPU's are pretty fast nowadays so you probably won't notice any problems until you start getting hundreds of objects (also, depends on how expensive your collision detection algorithm is). If you start getting latency issues, you might want to look into a [url="http://en.wikipedia.org/wiki/Quadtree"]Quad Tree[/url]. This will reduce your search to O(LogN) time. I wrote a quad tree for the first time a few days ago (compiled and worked the first time!!!) and it was suprisingly easy to code up (I figured it out on pen and paper before writing the code).

I also noticed that you algorithm isn't checking an object for self reference before doing collision detection checks. You might be doing that check in your collision detection function, but if you're not, you're going to always get an 'true' when checking for collision against yourself.

In my collision detection checks, I create a "collision record" for each collision I detected and then create a list of these collision records (to accumulate multiple collisions). Then, I run my lists of detected collisions into a collision handling class which then figures out how to process the collision based on the list of collision records (objects can be static (like a wall), moving and with mass (like an asteroid), or ethereal (like a bonus pickup item), or explosive (like a bomb or missile)).
0

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  
Followers 0