Box2D: Best way to get velocity that an object had *right before* a collision?

I’m adding this mechanic in my (physics-based) platform game where the player can bump into a button in order to push it… but I just don’t want any type of collision between the player and the button to trigger this “push” event. I want there to be a force required to trigger the push for it to seem more realistic.

The problem is that once the collision happens, the velocity of the player immediately becomes zero. Whether I try to resolve the action through preSolve() or beginContact(), the velocity is still zero.

The obvious solution here is to maybe try and constantly keep track of the player’s velocity and use the most recent value right before a collision happens… but idk… it seems like too much of a brute-force logic.

Might there be a more graceful way to solve this problem?

shit… sorry I made a mistake, I was looking at the velocity of the wrong body which is why I thought there was zero velocity -_-

You could give moving objects a Momentum property (a vector) that gets exchanged with collidable objects during collisions.