Skip to content

btKinematicCharacterController::getLinearVelocity() returns displacement, not velocity #55

Description

@Sweetzonzi

Description

getLinearVelocity() of PhysicsCharacter directly returns m_walkDirection, but m_walkDirection is used as per-step displacement in stepForwardAndStrafe (m_targetPosition = m_currentPosition + walkMove), without being multiplied by dt.

// getLinearVelocity() — returns m_walkDirection as-is
btVector3 btKinematicCharacterController::getLinearVelocity() const {
    return m_walkDirection + (m_verticalVelocity * m_up);
}

// stepForwardAndStrafe — m_walkDirection used as displacement
m_targetPosition = m_currentPosition + walkMove;

// playerStep — passed directly, no dt scaling
stepForwardAndStrafe(collisionWorld, m_walkDirection);

By contrast, the setVelocityForTimeInterval path (m_useWalkDirection = false) correctly multiplies by dt:

btVector3 move = m_walkDirection * dtMoving;
stepForwardAndStrafe(collisionWorld, move);

Result: every other CollisionObject's getLinearVelocity() returns m/s, but KCC returns m/step — off by a factor of dt.

Suggestion

If changing the native behavior is not feasible, the Javadoc should at least note that callers must divide by dt to recover actual velocity. The current Javadoc makes no mention of this discrepancy, making it a subtle trap for users.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions