Understanding Collision
by Chris Labombard · in Torque Game Engine · 12/16/2005 (11:20 am) · 8 replies
I know there are already threads about collision but I want to make sure my understanding of it is clear. So please tell me if the following explination is flawed or if I've missed something.
In an object's processTick(), if it moves it checks for collisions.
To do so, it asks the SceneGraph to return a working collision list for it's (the objects) collision object. (Convex::updateWorkingList() ) ... What the SceneGraph does in updateWorkingList is finds every object in the same bin that the object is in, and calls objectInTheSameBin::buildConvex() ...
In buildConvex(), an object checks to see if it's already in the workinglist for the passed in collision convex (the collision object for the original object). If it is, it doesn't do anything... If it's not, it adds itself.
The original object now, after updating it's working collision list has up to date collision information in it's Convex object which it can use at any time, in any function it wants to....
The Vehicle class (from which all other vehicles are derived) uses it in updatePos, by calling updateCollision which calls getCollisionInfo() which I'm assuming actually does the collision checks to find out if the object has collided with any of the collision objects in it's working collision list and populates the passed variables. It then uses the collisionList that was populated by getCollisionInfo to call resolveCollision which applies forces if the collision penetration was greater then the contact tolerance... and calls resolveContact which applies forces if the collision penetration was less then the contact tolerance (in other words it is really really close to colliding but not quite there yet so it gets pushed away anyways)
The Player class updates it's working collision list then calls updatePos. Then it checks if there's a collision with it's bounding box, to see if it can exit out early. If it doesn't find any collisions it exits.. if it does, it uses it's collision convex (mConvex) to check for collisions against everything in it's bin (getWorkingList() )... it then uses it's working collision list to check if it needs to step up onto anything. Then it moves parallel to the most parallel collision poly that it collided with... Then it cancels out velocity based on how parallel it is to that poly, and reorients it's velocity vector to be parallel with the collided poly.
Now, there are a few things I don't understand. Matt Farifax's simple collision tutorial object. It doesn't have a processTick function... does that mean the object can never move and collide with anything, just have something move into it? If I added a processTick function, would the SceneGraph automatically call processTick, allowing me to add functionality every tick? If I want an object that doesn't have collision, but contains several objects that can be collided with, I'm assuming that adding them, individually to the SceneGraph will take care of that. How do I get it to call processTick, just derive it from SceneObject, add it to the SceneGraph and give it a processTick function? Won't it also want a buildConvex() function? If I just have it do nothing, will it make the object uncollidable?
I know this is long winded. I just want to get a firm understanding of what's going on. Once I have something concrete here, it may help others understand what's going on as well.
In an object's processTick(), if it moves it checks for collisions.
To do so, it asks the SceneGraph to return a working collision list for it's (the objects) collision object. (Convex::updateWorkingList() ) ... What the SceneGraph does in updateWorkingList is finds every object in the same bin that the object is in, and calls objectInTheSameBin::buildConvex() ...
In buildConvex(), an object checks to see if it's already in the workinglist for the passed in collision convex (the collision object for the original object). If it is, it doesn't do anything... If it's not, it adds itself.
The original object now, after updating it's working collision list has up to date collision information in it's Convex object which it can use at any time, in any function it wants to....
The Vehicle class (from which all other vehicles are derived) uses it in updatePos, by calling updateCollision which calls getCollisionInfo() which I'm assuming actually does the collision checks to find out if the object has collided with any of the collision objects in it's working collision list and populates the passed variables. It then uses the collisionList that was populated by getCollisionInfo to call resolveCollision which applies forces if the collision penetration was greater then the contact tolerance... and calls resolveContact which applies forces if the collision penetration was less then the contact tolerance (in other words it is really really close to colliding but not quite there yet so it gets pushed away anyways)
The Player class updates it's working collision list then calls updatePos. Then it checks if there's a collision with it's bounding box, to see if it can exit out early. If it doesn't find any collisions it exits.. if it does, it uses it's collision convex (mConvex) to check for collisions against everything in it's bin (getWorkingList() )... it then uses it's working collision list to check if it needs to step up onto anything. Then it moves parallel to the most parallel collision poly that it collided with... Then it cancels out velocity based on how parallel it is to that poly, and reorients it's velocity vector to be parallel with the collided poly.
Now, there are a few things I don't understand. Matt Farifax's simple collision tutorial object. It doesn't have a processTick function... does that mean the object can never move and collide with anything, just have something move into it? If I added a processTick function, would the SceneGraph automatically call processTick, allowing me to add functionality every tick? If I want an object that doesn't have collision, but contains several objects that can be collided with, I'm assuming that adding them, individually to the SceneGraph will take care of that. How do I get it to call processTick, just derive it from SceneObject, add it to the SceneGraph and give it a processTick function? Won't it also want a buildConvex() function? If I just have it do nothing, will it make the object uncollidable?
I know this is long winded. I just want to get a firm understanding of what's going on. Once I have something concrete here, it may help others understand what's going on as well.
About the author
I have been a professional game programmer for over 5 years now. I've worked on virtually every platform, dozens of games and released a few of my own games, including 2 iPhone titles and a title waiting release on Big Fish Games.
#2
12/16/2005 (8:55 pm)
Ben - That sounds great. I can't wait :)
#3
If you want to get collision, then yes, you do a buildConvex call to the Container (call getContainer()), and process the resulting convexes.
The SceneGraph has nothing to do with processTick - the ProcessList code does. Make sure you add yourself to the appropriate process list, either client or server. Most leaf classes already have this done.
Hope this helps. :)
12/17/2005 (1:35 am)
Check out tdn.garagegames.com/wiki/TGE/Collision. To answer your question in particular, yes, Matt's object only responds to collision queries, but does nothing itself.If you want to get collision, then yes, you do a buildConvex call to the Container (call getContainer()), and process the resulting convexes.
The SceneGraph has nothing to do with processTick - the ProcessList code does. Make sure you add yourself to the appropriate process list, either client or server. Most leaf classes already have this done.
Hope this helps. :)
#4
I guess the only way I'm going to figure out how to actually code what I need is to sit down and code it.
Thanks for all the great info, I'm sure I'll read it multiple times as I wrestle to create my beast. :) I'll post back here with more questions, I'm sure.
12/17/2005 (7:56 am)
Ben - It helps broaden my understanding of what's happening and helps a little at putting me in the right direction to actually do it but it still leaves me asking a ton of questions about how to actually implement it. I guess the only way I'm going to figure out how to actually code what I need is to sit down and code it.
Thanks for all the great info, I'm sure I'll read it multiple times as I wrestle to create my beast. :) I'll post back here with more questions, I'm sure.
#5
But it's all pretty straightforward, just geometry in different spaces, and there's a lot of examples in the engine on how to do it. Never forget to visualize. A day's work visualizing the problem will save you days of painful debugging..
And any notes you might want to put on TDN would be welcome. :)
Good luck!
12/17/2005 (12:03 pm)
You're probably right. There's many ways to do it, all different - and once you get the convexes, the battle has just begun. :)But it's all pretty straightforward, just geometry in different spaces, and there's a lot of examples in the engine on how to do it. Never forget to visualize. A day's work visualizing the problem will save you days of painful debugging..
And any notes you might want to put on TDN would be welcome. :)
Good luck!
#6
I cannot go to tdn.garagegames.com/wiki/TGE/Collision
How can I do??
Thanks
12/18/2005 (8:47 pm)
@Ben Garney I cannot go to tdn.garagegames.com/wiki/TGE/Collision
How can I do??
Thanks
#7
12/18/2005 (9:06 pm)
What happens when you try?
#8
This is assuming you're a TGE owner
12/19/2005 (3:35 am)
You may need to click the login link, which will log you in and redirect you to the homepage... After that click back and refresh and it should load the right page.This is assuming you're a TGE owner
Associate Kyle Carter
I think I'm going to turn my reply here into a TDN page. So you might have to wait a day (I opened this thread much earlier in the day to reply and JUST got back to my desk...) but there'll be good info there. :)
Ben