collision impulse (solved)

Hey,

What would be the best way to precisely determine the impulse a collision generates? I've tried a few things:

- using a b2ContactResult
But I'm not always getting reading of a result. Sometimes it just doesn't seem to happen?
- using a b2ContactPoint (with b2ContactListener.Add())

-> velocity doesn't seem to be consistent. Sometimes a 'slow' collision seems to give a higher value than a really fast one.
-> seperation seems to have the same problem. I tried making one of the to-collide objects' a bullet, but it's still not that great.


My best guess is still using b2ContactResult, but why doesn't it always work? I only get a few traces through, after that, it seems to just stop detecting collisions, for that specific object. When I spawn a new object, it works a few times with that object again.

Thanks!
You should get a PostSolve every frame. If you are not, you need to investigate why. Are you sure your bodies are not going to sleep.
BorisTheBrave wrote:
You should get a PostSolve every frame. If you are not, you need to investigate why. Are you sure your bodies are not going to sleep.


The problem persists when I disallow my bodies to sleep. Right now, I keep track if one of my b2Bodies is colliding with another. I'm using the b2ContactListener as superclass for my own listener class. This class notifies my main game class whenever a collision takes place, and my main game class stores these collisions in a vector.

Immediately after the physics step (world.Step(..)), all these collisions are evaluated.

When I listen to any other of the collision listeners (Add, Remove, Persist) Everything seems to be fine.

When I listen to the Result collision, a bunch of collisions are registered (traced in my case), but after a while, they just stop working.

hope I'm doing something wrong here :S. Please tell me if I can say anything to make the problem clearer!

Thanks in advance!
I've done some testing and I found out this:

The problem occurs when one of the two colliding objects is already colliding to another (in this case static) object.

I have my main character object - I can let him fly around.

Then there's a boulder that falls from the sky,

and finally 3 static objects - ground, left wall, right wall. When the boulder drops down, the collisions are always traced. However, once the boulder is lying on the ground and colliding with it, I only get these collisions. I made it clear by making my boulder gravity-less. Could this be a bug, is this expected behaviour or am I doing something wrong?

Thanks!
I fixed the problem. The b2ContactResult needs to be copied, instead of remembered by using a vector. I remember reading something about this, so sorry for any of your time I wasted.
Ok, glad to hear problem is solved.

Original thread: https://box2d.org/forum/viewtopic.php?t=4456