Get velocity of a controller

I’m using PhysX 3.3.0.

My player character is a capsule controller and I need to be able to retrieve controller’s actual velocity, which seems a lot harder to accomplish than it should be.

I’ve tried retrieving the velocity of the actor associated with the controller after the main simulation of the scene, however that just returns bogus values, most likely due to the fact that a controller is just a kinematic actor under the hood.

Now, the only alternative I can think of would be to keep track of the velocity myself, but that’s not that simple. I can easily keep track of my own changes to the velocity, e.g. velocity applied via movement inputs. However that’s only accurate as long as the controller doesn’t collide with anything. After moving the controller via the move-function, the controller’s velocity may have been changed by collisions with the floor, or a wall etc. The move-function returns collision flags, but they only tell me whether there was a collision somewhere to the sides, the bottom or top, but that’s not accurate enough to derive the new velocity manually.

This seems like a rather large oversight, so maybe I’m just missing something here. How can I keep track of a controller’s velocity accurately if PhysX doesn’t provide a function to do so?

I’m not sure that’s relevant, but according to the controller position changes, you can determine its velocity.

PxVec3 computeVelocity(PxVec3 previousPosition,PxVec3 currentPosition, float elapsedTime)
{
return (currentPosition-previousPosition)/elapsedTime;
}

I’m not sure it can help, but I hope so.