How to setup a gun in first person shooting?
How to setup a gun in first person shooting?
Could u give me some example which way to put a gun on screen for first person shooting game?
thank
thank
No, you need to load model and then the gunNode mentioned before refers to the ISceneNode (or whatever) that points to that model.
Also, remember to scale the gun nice and small and then reposition it so it's offset nicely from the camera and looks realistic. Making it small will stop it disappearing through walls when you walk into them!
Also, remember to scale the gun nice and small and then reposition it so it's offset nicely from the camera and looks realistic. Making it small will stop it disappearing through walls when you walk into them!
Its done simply by attaching the gun node to the camera with the setParent() function.
Code: Select all
camera = scene_manager->addCameraSceneNodeFPS(0,100,500,-1, keyMap, 8);
/* ... load gun model etc ... */
gunnode->setParent(camera);
Then to offset it you just call the gunNode's setPosition() method with some small values. It can take quite some experiementing with different values to even see the gun on the screen sometimes as the offset values you give it may offset it to behind the camera and then you'll never see it, so try giving it something like +/-10 for each value (X and Z only probably, 0 on the Y axis should probably make it at least visible by the camera) and see which combination of those brings it in front of the camera then you can tweak each one by one to line it up nicely.
problem with collision detection for my gun
i've wrote something to not allow a gun disapear into the wall but it's work only when i walk straight to the wall but when i turn left ,right it's dispapear into wall.
do u have the better way to detect wall by gun?
note :
GunNode=IsceneNode
MapSelector=Q3map octreeTriangleSelector
Code: Select all
//------ ตรวจสอบการชน
Box3D box=GunNode.BoundingBox;
Vector3D radius=box.MaxEdge-box.getCenter();
ISceneNodeAnimator animGun=smgr.CreateCollisionResponseAnimator(MapSelector, GunNode,radius
,new Vector3D(0, -3, 0),
new Vector3D(0, 50, 0), 0);
GunNode.AddAnimator(animGun);
note :
GunNode=IsceneNode
MapSelector=Q3map octreeTriangleSelector
Alright, got a gunNode in and working... Thanks, was really quite simple once i figured it out
Have i forgotten anything important?
Code: Select all
// gunNode
scene::ISceneNode* gunNode = smgr->addAnimatedMeshSceneNode(smgr->getMesh("d:/Temp/Irrlicht Models/tommygun2/tommygun.3ds"));
gunNode->setMaterialTexture(0, driver->getTexture("d:/temp/irrlicht models/tommygun2/tommygun_skin.jpg"));
gunNode->setParent(camera);
gunNode->setPosition(core::vector3df(5,-12,17));
gunNode->setMaterialFlag(video::EMF_LIGHTING, false);
gunNode->setScale(core::vector3df(0.38,0.38,0.38));
gunNode->setRotation(core::vector3df(-80,5,7));