i want to implement a FPS Camera wich has collision detection with my map. ok i got the map (octree, bsp) in newton and collision detection works fine with testcubes. I also added a camera and a character controller but i don't really understand how they work. I think I'm doing it completely false because I don't understand the principle which stands behind the concept. I got the code from the IrrNewt character controller example.
If I do nothing after the map shows up, the camera goes on the ground (because of the gravity) but when I move (arrow-keys) it seems like the camera "leaves" the newton primitve and it can fly through walls and is not affected by gravity. If I'm lucky I can get into the primitve again (which hasn't moved) and it's affected by gravity or testcubes which hit the camera. I don't know how to make the camera stick in the newton primitve or how to make the primitve a child of the camera.
maybe someone can give me some hints on how I get this thing working or some simple tutorials which are focused on this problem. I think this is a well known question because who doesn't want a fps camera which does collision detection but i couldn't find anything useful on google or the board search, IrrNewt seems kind of "dead".
Thanks in advance,
lukrop
here's the code I'm using
Code: Select all
scene::IAnimatedMesh* mapMesh = core->getSmgr()->getMesh("maps/20kdm2.bsp");
scene::ISceneNode* mapNode = core->getSmgr()->addOctTreeSceneNode(mapMesh->getMesh(0));
mapNode->setPosition(core::vector3df(mapPosition));
scene::ISceneNode* camera = core->getSmgr()->addCameraSceneNodeFPS(0,80.0f,200.0f,-1);
// camera->setPosition(core::vector3df(camPosition));
nWorld = irr::newton::createPhysicsWorld(core->getDevice());
irr::newton::Hidden::SetDevice(core->getDevice());
newton::SBodyFromNode mapData;
mapData.Node = mapNode;
mapData.Mesh = mapMesh->getMesh(0);
nMapNode = (irr::newton::ITreeBody*) nWorld->createBody(mapData);
newton::SBodyFromNode cameraData;
// irr::newton::ICameraBodyFPS* newtonCam = nWorld->createCameraFPS(cameraData);
// newtonCam->addForceContinuous(core::vector3df(0, -30.0f, 0));
// newtonCam->setPosition(camPosition);
cameraData.Type = newton::EBT_PRIMITIVE_CAPSULE;
cameraData.Node = camera;
charControl = nWorld->createCharacterController(nWorld->createBody(cameraData));
charControl->setRotationUpdate(false);
charControl->setContinuousCollisionMode(true);
nWorld->getUtils()->avoidRotationOnAllAxes(charControl);
irr::newton::IMaterial* cameraMaterial;
irr::newton::IMaterial* mapMaterial;
cameraMaterial = nWorld->createMaterial();
mapMaterial = nWorld->createMaterial();
charControl->setMaterial(cameraMaterial);
nMapNode->setMaterial(mapMaterial);
cameraMaterial->setElasticity(mapMaterial, 0.0f);
cameraMaterial->setFriction(mapMaterial, 0.0f, 0.0f);
cameraMaterial->setSoftness(mapMaterial, 1.0f);
charControl->setClimbStairForce(core::vector3df(0,4,0));
charControl->setStairMaxHeight(40);
charControl->addForceContinuous(core::vector3df(0,-30.0f,0));