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

Collision Detection for Rotating Objects

8 posts in this topic

I am trying to figure out how to handle collision detection when the objects involved can have rotational motion. I used the following method first:

move
if intersecting then
resolve intersection using the mtd and collision normal
calculate response velocities
endif

Rotational motion was handled just fine, but I couldn't figure out how to support more than two objects. The problem was, one object's intersection could be resolved, but that resolution would put it inside of another object, that object would put it inside of another object (or even the first one it intersected with) and so on... There was also the problem of keeping track of what time the simulation was currently at inside the timestep.

I then moved on to a dynamic SAT test:

if will intersect then
move object to point of intersection
calculate response velocities
endif
move the rest of the way

This had the potential to solve the multiple object problem, as well as the current time problem. However, a rotating object can now "dig" its way through solid objects. This could be fixed by checking for intersection and resolving it with the mtd, but then we are back to the original set of problems.

I have read a lot about both physics and collision detection recently, but unfortunately everything has been a bit vague on how you are supposed to setup the whole system. How do you solve this problem?

I should note that I did find this topic: http://www.gamedev.net/community/forums/topic.asp?topic_id=539913 It was helpful to a certain extent, but it didn't answer my question.
0

Share this post


Link to post
Share on other sites
Hi VBStrider,

I'm wrestling with exactly the same issue at the moment. I think the best (easiest) approach might be an iterative one, whereby you make several passes over the objects, each time resolving any new collisions that arose from your previous set of resolutions, until no objects interpenetrate. The problem is, this can create quite long chains of object resolution when many objects collide. I'm still researching the topic but there are probably many optimisations that can be made with this approach.

I don't bother to find the time of penetration in my physics code; for objects moving at reasonable speed I think it's ok to just discard the rest of the timestep's movement. It vastly simplifies the object update process, and tiny fractions of a timestep left over make no discernable difference, especially when you're moving objects about in order to resolve penetrations anyway.

If you find out any more concrete info on the topic I'd be interested to hear it.
0

Share this post


Link to post
Share on other sites
When resolving the intersection you should not change the position of your bodies instead change the velocity right before the intersection.

Assuming your intersection occurs at time t_c only integrate object positions to t_c - delta where delta is some small value. Then you should calculate the collision response, which changes the velocity of the two bodies and you can continue your simulation. Even if this sounds easy, the tricky part is that you must make sure that your collision response guarantees you that it prevents penetration.

Handling multiple contacts can also be handled this way. You simply perform the collision detection / response until you can integrate to the end of your frame. With many objects you might need to do some tricks to prevent microcollisions (i.e. collisions that happen a lot during one frame).

Hope this helps.
0

Share this post


Link to post
Share on other sites
I have changed the system according to your directions to look like this:

while dt > 0
if will intersect then
if time of first intersection is within dt then
integrate to time of first intersection
dt = dt - time of first intersection

if objects are colliding then
calculate response velocities
else
integrate over dt
dt = 0
endif
else
integrate over dt
dt = 0
endif
else
integrate over dt
dt = 0
endif
loop

It can still dig through the other object though. Here is the demo: http://www.ifthensoftware.net/invisibleman/PhysicsTestbed.zip
0

Share this post


Link to post
Share on other sites

while dt > 0
if will intersect then
if time of first intersection is within dt then
integrate to time of first intersection
dt = dt - time of first intersection


Are you integrating here right to the time where the intersection occurs? You might get a problem due to limited precision in floating point arithmetic. E.g. the time you get from your collision detection is not right before the intersection, instead it might be the time right after the collision. Thats where you need the '- delta' of my previous post.

This looks odd to me:

if objects are colliding then
calculate response velocities
else
integrate over dt
dt = 0
endif

At this point you should already know, that the objects will collide. Therefore you do not need to check again, instead resolve it immediately.

It all should fit into something like this:

while dt > 0
tc = calc_next_collision_time
if tc < dt
integrate to tc - delta
correct velocities

dt = dt - tc
else
integrate to dt
dt = 0
end if
loop

Even though this looks simple, it can get quite messy to get it robust as you'll have to make sure floating point arithmetic is not fooling you.

This all assumes that bodies never penetrate each other. There is also another way of doing it, in which penetration is allowed but additional forces are applied to push bodies out of each other. Such an approach is used by Box2D and Chipmunk Physics. You might want to look into their references.

Sorry, I couldn't run your example as I don't have Windows flying around here right now. I'll have a look at it later.
0

Share this post


Link to post
Share on other sites
The objects could be touching, in which case the time of collision will be 0. That's what the second collision test is for.

The main problem is that the time of collision is only being calculated for linear motion, not angular motion. Because of this, the object can rotate into an object. Dynamic SAT does not support rotating objects, and so the object needs to be treated as though the rotation happens instantly at the end of the timestep. Checking for intersection causes the original problems.

There should be a well known solution to this problem... I see games use rotating objects all the time.
0

Share this post


Link to post
Share on other sites
Quote:
Original post by VBStrider
The objects could be touching, in which case the time of collision will be 0. That's what the second collision test is for.


You could modify your collision detection method such that it tells you that no collision will occur for a given time (simplest method for this would be to return -1 in this case). This second check is not needed as you should only advance your simulation to a state where there is no collision if you do not have any correction methods for existing penetrations.

Yeah, getting rotational collisions properly to work is quite difficult. But try to get that done first. Testing computing collision response when you do not have a robust collision detection is not ideal.

For detecting collisions caused by rotations, you could use a bisection method to find the time of impact. This will involve frequent integrations and resetting of the states, but should be okay performance wise. There are a few threads here about collision detection of rotating bodies. It surely is possible, but is definitely harder than a dynamic SAT.

It works in a lot of games, but remember, that games in general do not simulae the real world, instead there are a lot of hacks to make games just look like reality.

0

Share this post


Link to post
Share on other sites
The second check calculates the dot product between the collision normal and the relative velocity. If the result is negative, they are colliding. Otherwise they are moving apart and there is no collision.

Thanks for the pointer! This is my current reading list (most likely in this order):
Physically Based Modeling: Principles and Practice
Section 9.5 of Real-Time Collision Detection, "Gilbert-Johnson-Keerthi Algorithm"
Ray Casting against General Convex Objects with Application to Continuous Collision Detection
Continuous Collision Detection and Physics
Impulse-based Dynamic Simulation of Rigid Body Systems

If anyone has recommendations for my reading list (new articles, read this instead of that, etc.) please let me know :)
0

Share this post


Link to post
Share on other sites
I have ran into a problem with using bisection to find the time of intersection. If one object has a great enough acceleration towards the object it collides with, the impulse will not keep it away for very long and it will end up colliding again within a very short amount of time. A single step ends up looking like this:
Integrate from t0 to t1.
Collision found at t0+dt1 and resolved.
Integrate from t0+dt1 to t1.
Collision found at t0+dt1+dt2 and resolved.
Integrate from t0+dt1+dt2 to t1.
Collision found at t0+dt1+dt2+dt3 and resolved.
...

This happened to me almost immediately, so it has to be a commonly known problem. However, the resources I have found have not mentioned it, much less how to solve it.

EDIT: Nevermind, the problem was misdiagnosed. It ended up being caused by an incorrectly calculated collision normal.

[Edited by - VBStrider on November 15, 2010 2:03:16 AM]
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