Page 1 of 1

How to setup a gun in first person shooting?

Posted: Mon Sep 11, 2006 5:08 pm
by bug_aonz
Could u give me some example which way to put a gun on screen for first person shooting game?

thank
:D

Posted: Mon Sep 11, 2006 5:12 pm
by Dibalo
gunNode->setParent(cameraNode);

thank

Posted: Mon Sep 11, 2006 5:26 pm
by bug_aonz
i can do it
Thank :D

Posted: Tue Sep 12, 2006 10:19 pm
by CeeRo
Is there a gunNode in Irrlicht already?

Posted: Tue Sep 12, 2006 10:22 pm
by JP
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!

Posted: Tue Sep 12, 2006 11:54 pm
by CeeRo
K, still a bit ways off for me then I guess, I can figure out how to load a model on the map I guess, but dunno how to attach it to the camera and offset it yet (I picked up both C++ and Irrlicht a couple days ago).

Have you got a small piece of code to demonstrate maybe? Would be much appreciated :)

Posted: Wed Sep 13, 2006 12:31 am
by zeno60
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);

Posted: Wed Sep 13, 2006 8:51 am
by JP
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

Posted: Wed Sep 13, 2006 3:56 pm
by bug_aonz
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.

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);
do u have the better way to detect wall by gun?
note :
GunNode=IsceneNode
MapSelector=Q3map octreeTriangleSelector

Posted: Wed Sep 13, 2006 7:02 pm
by JP
Do what i said, just make the scale of the gun node small enough so it doesnt go through the wall anymore, you'll then have to tweak the offset you had the gun at a bit to get it back to looking the same way as before, but it's not hard.

Posted: Thu Sep 14, 2006 1:32 am
by CeeRo
Alright, got a gunNode in and working... Thanks, was really quite simple once i figured it out :)

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));
Have i forgotten anything important?

Posted: Thu Sep 14, 2006 9:35 am
by JP
That all looks sensible, so if it looks good on screen then it should be fine! :D