一、介绍
该示例项目的主要目的是模拟一个角色在行星上面移动时的模拟:
主要对象有:
行星(定义了质心)
角色(使用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;
在跳跃过程中碰到物体时,停止跳跃模拟,采用匀速落体模拟
个人认为这个地方其实是需要一定的改进的,对于落体时长较长的地方,其模拟将会不够真实