一、介紹
該示例項目的主要目的是模拟一個角色在行星上面移動時的模拟:
主要對象有:
行星(定義了質心)
角色(使用CapsuleController)
角色行為有:跳躍、重力
二、實作思路
物體朝向:每幀計算目前物體的朝向(計算物體質心與行星質心兩點構成的向量setUpDirection)
mCCT.setUpDirection(upVector);
物體跳躍高度:采用重力加速度來模拟跳躍
物體移動時高度:在跳躍狀态時采用跳躍時模拟;跳躍結束後,采用勻速落體模拟(恒定減去重力g*間隔時間t計算下降高度(upDisp *= -9.81f * dtime))
const PxF32 heightDelta = gJump.getHeight(dtime);
// shdfnd::printFormatted("%f\n", heightDelta);
PxVec3 upDisp = upVector;
if(heightDelta!=0.0f)
upDisp *= heightDelta;
else
upDisp *= -9.81f * dtime;
const PxVec3 disp = targetKeyDisplacement + targetPadDisplacement + upDisp;
在跳躍過程中碰到物體時,停止跳躍模拟,采用勻速落體模拟
個人認為這個地方其實是需要一定的改進的,對于落體時長較長的地方,其模拟将會不夠真實