0

I'm using PhysX 3.3.0.

My 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?

// EDIT

This is how I'm grabbing the velocity after the scene simulation:

void ControllerPhysObj::UpdateVelocity()
{
    physx::PxRigidDynamic *actor = m_controller->getActor();
    physx::PxVec3 vel = actor->getLinearVelocity();
    m_velocity.x = vel.x;
    m_velocity.y = vel.y;
    m_velocity.z = vel.z;
}

m_controller is a PxCapsuleController.

Silverlan
  • 2,783
  • 3
  • 31
  • 66

1 Answers1

0

The question is how do you move your controller. If you are using PxController::move then you can easily determine velocity by dividing actual vector of displacement by the time of update frame.

Actual vector of displacement is difference in positions of your capsule before and after the PxController::move was called.

Time of update frame is (most likely) the time you providing for PxScene::simulate (most likely because you may have more elaborated approach for update cycle).