How do we pull info out of the engine?

Dec 2, 2007 at 4:22 PM
Hey there - we're in the process of wrapping up a simple 3d game using your OOPS framework for the physics. We ran into a snag and were hoping you could offer some suggestions: how do we get a list of new collisions after each Update() call? We need to find out when new collisions occur so we can perform logic like sound effects, health adjustments, etc... but the Collision[] list from the collisionContext is always massive, because of all the objects lying on the ground.

We tried clipping all the objects that weren't stationary, but the objects at rest on the floor apparently aren't stationary, but always constantly and imperceptibly moving down due to gravity.

Is there an efficient way that you know of, to gather new collisions from each Update pass?

Thanks so much.
Coordinator
Dec 4, 2007 at 1:57 AM
I plan implementing a simple way to detect just new collisions, but for now, you can keep track of collisions with a time (gameTime.TotalElapsedTime perhaps) and the rigid body, shape or object either of these two represent. The time property would represent the time the collision occurred and the object would be the object it collided with. Don't fire the event (i.e., sound effect) if a certain amount of time hasn't elapsed or if the object(s) you need to keep track of hasn't changed.

In your case, it sounds like you would assign the "object" property and reset the "time" property anytime the ground gets hit. You could do this by implementing the ICollisionCallback interface and passing it to the constructor of the physics component. The MainMenuScreen does this.

I'm sure others have ideas as well along these lines short of rewriting the framework. :)

Good luck! Let me know how it turns out!
Dec 4, 2007 at 1:11 PM
Wow... it seems so obvious now. We were trying to modify the class, and get access to the context... when we had this gorgeous interface just staring us in the face! Thanks so much!
Dec 9, 2007 at 12:18 PM
What I do is I only care about contacts that have a high relative velocity (objects that don't have enough speed won't make any sound) and also if there is more than one contact between two objects I use the average of them for the position of the 3D sound emitter.
There is also another way: In some engines (Bullet, ...) there is a ApplyImpulse*() method in RigidBody class that is used when resolving the collisions, you can use that to be notified of impulses greater than a certain magnitude.

Cheers.
Coordinator
Dec 10, 2007 at 4:17 PM
Hi KamiSama,

Thanks for responding! The first solution you stated is the route I'm planning on implementing...but the second intriques me as well. I didn't even think about notifications at the time of impulse application. I'll be looking into this as well!