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

Swept AABB collisions and the crack problem

5 posts in this topic

Hello! Copying this over from a post I made on tigsource, hopefully I can articulate my troubles sufficiently.. I've been working on a tile based game that might end up involving high velocities and decided to go for a continuous collision detection sort of model, due to some nasty looking behaviour where the character approaches the edge of a tile too fast. I've done some searching around at various implementations of CCD, and it seems to vary from example to example.
Having looked at ThemsAllTook's implementation and guide for swept AABB collisions [url=http://sacredsoftware.net/tutorials/Collisions/CollisionsPart1.html]here[/url] I understood the theory but found the actual intersection check a little hard to follow, particularly with the use of previous positions as opposed to velocities - but I suppose they're equivalent. I've ended up settling for an amalgam of that and a [url=http://www.gamedev.net/page/resources/_/technical/game-programming/swept-aabb-collision-detection-and-response-r3084]GameDev article on swept collisions[/url] (which I found a bit more intuitive).

The trouble is, I'm finding it difficult to overcome the surface area 'stubbed toe' problem. I figured I could find out minimum translation distances from new positions and intersection positions, but sorting by the surface area calculated in that fashion (technically just on one axis in the case of my implementation) doesn't seem to quite work and I get edge 'stopping' even in the case of just one collision.

Here is a demo of it in action, you can control it with arrow keys or the mouse - http://www.filz.us/view/1e940c5a-764/. The most noticable effect is if you slide up against one side, then slide off it on that axis and try to slide back - you'll get stuck on the corner.

Another thing I wasn't quite clear on was the fact that I found myself having to set the object's position to its corrected one, is that standard for a CCD simulation? I wasn't sure if I'd only be dealing with negating velocities and so on, it just struck me as odd. Without the positional correction in the collision resolution, I'd get issues with persistent forces acting on the body causing it to sink through other AABBs.

This is the simplified code, if it's at all decipherable I'd really appreciate it if somebody could point out how to go about solving the problem, and if my implementation of CCD even makes sense - http://pastebin.com/xWFsuxWm

1

Share this post


Link to post
Share on other sites
With an exact time of impact for known colliding features there should be no need for "corrected" positions and other hacks: just apply forces and torques and continue the simulation. If you paid the price of exact CCD calculations, you should reap the benefit of really correct physics.
1

Share this post


Link to post
Share on other sites

Of course one is left wondering what "exact time of impact" means since timing is one of the first monumental issues to solve when dealing with realtime physics. We could go on noticing we're talking about a logic-controlled object for which standard physics often has limited meaning. Or ask ourselves what "really correct physics" even is. And what about accurate computing on FPU?

 

Personally I'm bold on this topic. All those dudes telling you can do physics yourself (especially by doing canonical math) are doing a disservice to the community.

 

The problem OP notes is a clear demonstration of how canonical math work. Let me show you visually what happens:

[attachment=16042:2013-05-31 10_27_08-Greenshot.png]

The small box here is being pulled to the mouse pointer. Small box upper left corner, when unconstrained will match cursor hotspot.

Expected behaviour: slide to a nerby position (probably on right box lower edge).

What happens: got stuck over the corner between the two boxes to the left (as shown).

Observation: as soon as the pointer moves down a few pixels, crossing right box bounduary, the small box is able to reach the cursor.

 

This behaviour is mathematically sound and correct to a certain degree. How exactly doing more accurate math solves the problem is unclear to me.

What a physics library would do at this point is to put aside the math for a second and consider the two collision primitives are really meant to be contiguous and filter collision accordingly. This does not always work however. That's an indication on how difficult this problem is.

 

So my suggestion is: screw all that. Get some physics library you can use in flash and leverage the effort of someone focusing to this problem specifically. BTW, I've been told flash is going to have rough times ahead.

But supposing you cannot do that, I'd get the hit, and check all other collision primitives for being nearby the one I hit and if a match is found, ignore the collision.

Hopefully this will allow the box to slide a few frames and, provided your de-encroaching works it will be correctly pulled "down" and there should be no problem from now on.

Edited by Krohm
1

Share this post


Link to post
Share on other sites

@ LorenzoGatti That was my instinct, too, which made me wonder as to the specifics of my implementation, and where I'd.. gotten it wrong. With constant forces such as the mouse joint, it would bounce off on an initial swing (if the response was made elastic) then sink straight through. Is it to do with the ordering of resolving collisions, applying outside forces / impulses, and the integration itself?

 

@Krohm I understand your point fully about tools and libraries already existing to tackle this problem (box2d suffers from this also, you have to use edge chains I believe for static objects in sequence). However I do also view this as a learning experience and I value the process of solving the problem. I don't have a tight deadline or anything, I quite enjoy getting lost in the intricacies of physical simulation!

 

The main issue I have at this point is that I've seen from SacredSoftware's implementation that it is possible to get a more general solution, through the use of sorting collision priority based on which collision has a greater surface area of penetration in a given timeslice (or rather, time step with a threshold, as of course CCD would only really solve one at a time so you have to step forward and test a little). What puzzles me is the two facts that a) It does not function correctly without positional correction, and b) It gets stuck on an edge even in the case of a single box. I suppose if it's correcting it to the EXACT edge position, when it moves back down it would maybe get snagged on a corner? But is that correct behaviour?.. It's not common to many others, which makes me think the penetration resolution isn't quite correct, in terms of initial contact times.

1

Share this post


Link to post
Share on other sites

Upfront, I am not an expert. But I was thinking, if your goal is to find the collision point closest to the desired destination, given that you're working with AABBs there are only two directions you can take to get closer to the destination. Find the initial collision point, then try going in one of the two cardinal directions from that collision point. If you travel right from the "crack" in the diagram above there should be no collision.

1

Share this post


Link to post
Share on other sites

I've always done 2D collision detection as a two step process. Usually X first, then Y, so in platformer type games you have a better shot of getting your toe onto a ledge before moving down. Really easy and 100% accurate and free of problems like this, at least until you start adding slopes, where horizontal movement causes vertical movement, which can either get you over a hill, or cause your head to run into something. It is possible to solve with 100% accuracy, but it's easier to just put restrictions on your levels (e.g. don't even put slopes where they'll wedge you against a ceiling). Also, an overhead game where moving up/down into slopes causes horizontal movement, will usually require a somewhat different approach than a platformer.

 

Having objects stand on top of eachother and push eachother around is the other main way to add difficulty... the update order becomes important if you don't want anything to lag by one frame from where it should be.

 

And for high velocity, just divide the velocity by the tile size, and call the collision function multiple times.

 

Another fun system I did one time was a billiards game where I'd test every pair of balls against eachother, calculating the time of collision with both their velocities accounted for... then update the whole simulation to the time of the first collision, and repeat until the full frame time elapsed. Really slow, but certainly solves the update order problem :)

 

But none of that compares to the pain that is 3D collision. Unless you keep all your levels axis aligned, you will have numerical accuracy problems. 99% of the time everything is fine, but every once in a while you do a sweep test, it says everything is fine, but after moving, doing an intersection test with the plane returns true. Or small velocities letting you creep up on a wall until you go through it. Or calculating a slide vector causing you to run into the same wall again. Near impossible to be 100% fall-through-proof, and usually requires various hacks checking for the various ways things can go wrong and attempting to correct the situation in a way that doesn't jar the player.

 

Anyway, I don't think there's a totally straightforward solution to the corner snagging problem in the system you're using, but you can try to understand why it's a problem, and devise a solution. IMO, the root of the problem is that you're considering each object individually, but it's only together that they create a continuous surface. The X velocity only gets cut because you're allowed to move inside of one rectangle just a tiny bit while checking against the other. The surface area test in that first article is what I would call a hack to deal with this particular situation that comes up. I'm sure there are others, but I'm not sure if there's a really clean and natural way to solve it.

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