• 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
bwhiting

Simple collision detection when 2 objects push body into eachother

6 posts in this topic

Probably a really easy question for you season pros, but I can't seem to think of an obvious solution to this problem.

 

Here it is in a simple form:

Imagine a rectangle travelling horizontally, it collides with another rectangle that is above it, overlapping it only slightly from above:

 

            _____

___      |        |

|     |     |-------|

|     |

|     |     ----->

|___|_______________

 

This will result in the object being pushed down into the floor (the penetration in the downward direction may be the smallest) which will lead to it being pushed back up by the floor.

 

How do you avoid this problem and ensure that the object stops dead on collision rather than gets pushed down.

 

I though about separating the collision into stages, testing only one axis at a time but that feels clunky.

 

Hold the phones, whilst writing this I think maybe I should never check the bottom side of the top body because its normal (if dotted with the direction of the other body) would show that they should never be tested against each other.

 

Maybe that is more important than I though, never check a face if its normal dot the direction is greater than 0? Am I on the right lines? Am only really dabbling here so not the end of the world if I can work it out. Thanks for your time.

 

smile.png

1

Share this post


Link to post
Share on other sites

I think this is quite a tricky problem. I see two solutions:

1. Design your levels in a way that this never happens. This is the case for most platformers. For example, if you have tile based levels, you would choose the player and tile size appropriately.

 

2. Take a continuos collision detection/resolution approach which prevents those objects from penetrating in the first place. E.g., speculative contacts.

0

Share this post


Link to post
Share on other sites

Thanks for the replies, 1 was the obvious solution and a perfectly acceptable one - I just figured there was an easy solution. 2, I have read a bit about this on wildbunny and it looks great but more complex than I was hoping was needed to fix the issue. (will get round to it at some point I am sure).

 

Any thoughts on the idea of using normals as a guide? 

0

Share this post


Link to post
Share on other sites

Using normal vs velocity as you describe won't work if you're still allowing intersection and then trying to resolve it after the fact I'm afraid, because what if the character jumps just before he reaches the block? Even if he doesn't jump he might still have a tiny amount of upward velocity due to floating point inaccuracy. This might cause you to put an epsilon in, which could then fail in some other subtle case.

 

Using continuous collision would be pretty straightforward if you only have axis aligned boxes and is possibly the only general solution to this problem. However, if you also have irregular collision shapes then you're likely to get into a world of floating point rounding hurt.

 

Another random idea - if you're only using rectangles then you could say that the top of the moving box starts off higher than the bottom of the other box and therefore can't have hit, but this only works for aligned boxes I think.

 

I also actually think your other idea of checking the x axis then the y axis could have legs. Of course it'll also fail if you then drop from above very fast onto a gap that isn't wide enough to fit down!

 

Designing around the issue is desirable but might not be possible if you want moving platforms or sliding doors, etc.

 

Wish I could give you a definitive solution but this is indeed quite a tricky problem.

0

Share this post


Link to post
Share on other sites

Continuous collision detection seems to be the only way. To avoid this you need to move your rectangle such that it never ends up clipping other geometry, so you need to know about the geometry when moving your rectangle which would seem to suit CCD naturally, which returns the minimum time until intersection or equivalently the farthest an object can travel before clipping the world, and when that happens you can handle both forces which will immediately cancel themselves out.

0

Share this post


Link to post
Share on other sites

Just like what the above posts mentioned, CCD will help you out.  Also, if you use separating axis tests, the last separating axis between the 2 boxes is going to be horizontal, and not vertical.  You should be able to take the "normalized last separating axis * penetration distance" and move the box to where constraints are satisfied.  Or move the box to it's "first time of contact."

 

Once you start having to deal with multiple contact points (e.g. box stacking), it'll get a little bit more complex....

0

Share this post


Link to post
Share on other sites

Thanks again for some thoughts there, looks like I  will have to look into CCD then.

The rectangles were just illustratory of the problem. More complex shapes and rotations should would also ideally be accounted for down the line.

 

I really thought there would be some logical (more obvious) solution to this kind of problem but I guess it is a well known issue.

 

I have some SAT collision code I wrote a while ago, seems pretty decent - not epic fast but good enough. 

Which reminds me, I haven't played that much in the world of 2D, more of a 3D guy really so on that note I have another small question semi related to my problem above.

 

Do people generally work in local space (transforming other bodies into their own space) or in world space when dealing with collisions in 2d. Or do people just work in world space only? Just curious as I would tend to want to use transforms but might be seen as overkill for simple 2D physics.

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