作者sqaure (sqaure)
看板GameDesign
标题[程式] CharacterControl会穿透地面?
时间Mon Dec 14 02:10:33 2009
最近正在尝试自己把PhysX整合到Ogre (不是用NxOgre)
但我把Character Control的那个Example整合到Ogre
每次我的Character Controller 都会穿越地面。
大部份的code都是从那个范例复制过来的,
唯一不同的地方就是terrain的部分
这是我create terrain的部分:
// Create ground plane
NxPlaneShapeDesc planeDesc;
planeDesc.group = GROUP_COLLIDABLE_NON_PUSHABLE;
NxActorDesc actorDesc;
actorDesc.shapes.pushBack(&planeDesc);
NxActor* terrain = gScene->createActor(actorDesc);
NxShape*const* shapes = terrain->getShapes();
NxU32 nShapes = terrain->getNbShapes();
while (nShapes--)
{
shapes[nShapes]->setGroup(GROUP_COLLIDABLE_NON_PUSHABLE);
}
此时,我建立的box都可以掉落在地面上,就Character Controller不能
初始Character controller:
NxCapsuleControllerDesc desc;
desc.position.x = pos.x;
desc.position.y = pos.y;
desc.position.z = pos.z;
desc.height = box_size.y +10; //height;
desc.radius = ( (box_size.x+box_size.z) / 2 ) / 2 ;//radius;
desc.skinWidth = 0.1f;
desc.slopeLimit = cosf(NxMath::degToRad(45.0f));
desc.stepOffset = 0.5f;
desc.upDirection = NX_Y;
desc.climbingMode = CLIMB_EASY;
desc.callback = &mReport;
mController = mManager->createController(scene, desc);
移动部分:
#define COLLIDABLE_MASK (1<<GROUP_COLLIDABLE_NON_PUSHABLE) |
(1<<GROUP_COLLIDABLE_PUSHABLE)
void MyCharacterController::Move(const NxVec3 &disp, NxU32 &flag)
{
mController->move(disp, COLLIDABLE_MASK, 0.001, flag);
}
建立箱子的部分:
// Create body
NxBodyDesc bodyDesc;
bodyDesc.angularDamping = 0.5f;
bodyDesc.mass = 1;
NxBoxShapeDesc boxDesc;
boxDesc.dimensions =
NxVec3((float)box_size.x, (float)box_size.y, (float)box_size.z);
boxDesc.group = GROUP_COLLIDABLE_NON_PUSHABLE;
NxActorDesc actorDesc;
actorDesc.shapes.pushBack(&boxDesc);
actorDesc.body = &bodyDesc;
想问问大家有什麽意见吗?
是CharacterController 的collision group不同?
但其他部份我都没有动过阿...
几乎跟example一模一样
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 140.122.184.243
1F:→ justben:我可以问一下const前面为何要加 *吗? 12/14 23:51
2F:→ sqaure:没有注意到这边过..应该是复制example的... 12/16 00:25