How to setup a gun in first person shooting?

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
bug_aonz
Posts: 6
Joined: Mon Sep 11, 2006 5:06 pm

How to setup a gun in first person shooting?

Post by bug_aonz »

Could u give me some example which way to put a gun on screen for first person shooting game?

thank
:D
Dibalo
Posts: 30
Joined: Sat Aug 12, 2006 2:31 pm
Location: Finland
Contact:

Post by Dibalo »

gunNode->setParent(cameraNode);
Dattebayo!!
bug_aonz
Posts: 6
Joined: Mon Sep 11, 2006 5:06 pm

thank

Post by bug_aonz »

i can do it
Thank :D
CeeRo
Posts: 11
Joined: Tue Sep 12, 2006 10:17 pm

Post by CeeRo »

Is there a gunNode in Irrlicht already?
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Post 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!
Image Image Image
CeeRo
Posts: 11
Joined: Tue Sep 12, 2006 10:17 pm

Post 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 :)
zeno60
Posts: 342
Joined: Sun May 21, 2006 2:48 am
Location: NC, USA
Contact:

Post 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);
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Post 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.
Image Image Image
bug_aonz
Posts: 6
Joined: Mon Sep 11, 2006 5:06 pm

problem with collision detection for my gun

Post 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
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Post 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.
Image Image Image
CeeRo
Posts: 11
Joined: Tue Sep 12, 2006 10:17 pm

Post 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?
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Post by JP »

That all looks sensible, so if it looks good on screen then it should be fine! :D
Image Image Image
Post Reply