Implementing Vehicle Wheel Sweeps for off-road game

To help others who may be in a similar situation, I did figure out some things.

  1. Where to put “bUseCheckedPhysXLibraries = true;” is in the file with the your project name + EditorTarget.cs. After rebuilding the engine with this, I was getting helpful error information in the Output window.
  2. It turned out that my issue was that I was not correctly allocating memory for the sweeps. When setting up the batched scene query for sweeps, use:


// Note that we need to use the second input for setting the sweep memory
PxBatchQueryDesc SqDesc(0, NumWheels, 0); // PxBatchQueryDesc (PxU32 maxRaycastsPerExecute, PxU32 maxSweepsPerExecute, PxU32 maxOverlapsPerExecute)


Reference: https://documentation.help/NVIDIA-Ph…QueryDesc.html

By the way, I found that using multiple vehicles would still cause the out of memory error. Hand-coding extra sweeps into the memory solved the issue, but it should have correctly calculated the sweep count from NumWheels. If anyone knows how to fix this, I would appreciate the advice.

This got the car driving, but it would tend to have its wheels fall through the world when around complex geometry. So, I added a “post” filter shader:



PxQueryHitType::Enum WheelSceneQueryPostFilterBlocking
(PxFilterData filterData0, PxFilterData filterData1,
    const void* constantBlock, PxU32 constantBlockSize,
    const PxQueryHit& hit)
{
    PX_UNUSED(filterData0);
    PX_UNUSED(filterData1);
    PX_UNUSED(constantBlock);
    PX_UNUSED(constantBlockSize);
    if ((static_cast<const PxSweepHit&>(hit)).hadInitialOverlap())
        return PxQueryHitType::eNONE;
    return PxQueryHitType::eBLOCK;
}


It is not a perfect solution but causes the wheel suspension to act properly in the large majority of off-road situations.

Finally, I want to note that @wuzzy was right about using a generated wheel collider. No other collider types worked. However, I did not end up going with this method because it seems to sweep from the (limited) edges of the collider, causing jerky suspension movement at low speeds. Instead, I found the setting “UsePhysAssetShape” caused very smooth motion at all speeds. Still not perfect, but it looked much better.

Hope this helps @yazhangmu and others also working on this. Without feedback on the forum I would not have gotten this far.