Adding Weapons to a camera, and hud to game

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
dejai
Posts: 522
Joined: Sat Apr 21, 2007 9:00 am

Adding Weapons to a camera, and hud to game

Post by dejai »

Ok I have this little FPS and you are just a camera. I want to know how to attach a weapon or a child mesh to that camera also how to rotate or cycle through several guns by pressing the 1 key 2 key and so on. Also how to create impact on a enemy mesh and after say 3 shots they die.

Maybe also how to add weapons to enemys.

Also with a Hud I have read the 2d sprite tutorial and have tried to insert a image into my game but failed... I got the image in but then the 3d game was frozenn...

Sorry I know this is a lot to ask I don't really want you to write my code just point me in the right directions maybe some examples. And documentation referances :D

Thanks for all your help :D
Programming Blog: http://www.uberwolf.com
Dances
Posts: 454
Joined: Sat Jul 02, 2005 1:45 am
Location: Canada
Contact:

Re: Adding Weapons to a camera, and hud to game

Post by Dances »

dejai wrote:Ok I have this little FPS and you are just a camera. I want to know how to attach a weapon or a child mesh to that camera also how to rotate or cycle through several guns by pressing the 1 key 2 key and so on. Also how to create impact on a enemy mesh and after say 3 shots they die.

Maybe also how to add weapons to enemys.

Also with a Hud I have read the 2d sprite tutorial and have tried to insert a image into my game but failed... I got the image in but then the 3d game was frozenn...

Sorry I know this is a lot to ask I don't really want you to write my code just point me in the right directions maybe some examples. And documentation referances :D

Thanks for all your help :D
Make a node a child of the camera, with a gun mesh. Stick it a little in front of the camera.

Use setVisible on your weapon nodes to change weapons.

Give your enemy mesh a health variable. Cast a line from the camera and if that line hits your enemy mesh reduce its health. When its health is 0 use some sort of kill function. You can just use setVisible again for a start.

Easiest way would be to include their weapon in the mesh and animate it. Give them some AI to decide when to fire and cast a line and see if it intersects with the player.

Did you draw your scene manager every frame? This should be in your main loop:

smgr->drawAll();
guienv->drawAll();
Catprog
Posts: 164
Joined: Wed Jan 31, 2007 9:07 am
Contact:

Post by Catprog »

Another option that you could look at is just place an bitmap for the weapon in the appropriate place
oldskoolPunk
Posts: 199
Joined: Wed Nov 29, 2006 4:07 am

Post by oldskoolPunk »

Make a node a child of the camera, with a gun mesh. Stick it a little in front of the camera.
When I try this, the node follows the camera, but does not rotate with it. How do you keep the node stationary in front of the camera?

dejai, did this work for you?
Signature? I ain't signin nuthin!
evilbobthebob
Posts: 10
Joined: Wed Jul 11, 2007 11:03 am
Location: UK

Post by evilbobthebob »

I want to do this as well. Here's the code I've got so far:

Code: Select all

scene::IAnimatedMesh* gunmesh = smgr->getMesh("gun.3ds");
scene::ISceneNode* gunnode = 0;

.........

if(gunmesh)
{
           gunnode = smgr->addAnimatedMeshSceneNode(gunmesh, gunnode);
           camera->addChild(gunnode);
           gunnode->setPosition(vector3df(0, 0, 0));
           //gunnode->setScale(vector3df(1, 1, 1));
}
As you can see, I've commented out the scale because I haven't had the mesh even displayed yet. I don't know about the position, either.
bob
Posts: 57
Joined: Fri Jun 08, 2007 4:17 am
Location: Jacksonville, Fl (USA)
Contact:

Post by bob »

I created this FaceTarget() function specifically for fixing my HUD icons in front of the camera. Just call FaceTarget( pCam->getTarget() )
evilbobthebob
Posts: 10
Joined: Wed Jul 11, 2007 11:03 am
Location: UK

Post by evilbobthebob »

Thanks. I'll have a go with that. :)
Bwahahahaha...the world is mine.


Maybe.


Well, maybe not.
evilbobthebob
Posts: 10
Joined: Wed Jul 11, 2007 11:03 am
Location: UK

Post by evilbobthebob »

Sorry for the double post, but although that code is great for HUDs, it isn't so hot when it comes to adding a 3D gun to the camera...if I'm worng, and I'm just being stupid (likely) please tell me :P
Bwahahahaha...the world is mine.


Maybe.


Well, maybe not.
bob
Posts: 57
Joined: Fri Jun 08, 2007 4:17 am
Location: Jacksonville, Fl (USA)
Contact:

Post by bob »

although that code is great for HUDs, it isn't so hot when it comes to adding a 3D gun to the camera
I'm not sure what you mean. Does the gun not stay fixed in front of the camera? I don't have a gun in my app, but I do have a compass and it stays put.

Of course, you do have more bob's in your moniker, so you have me beat there. :)
oldskoolPunk
Posts: 199
Joined: Wed Nov 29, 2006 4:07 am

Post by oldskoolPunk »

I discovered the confusion. The scene nodes do stay put when using Irrlicht's built-in FPS cam, but when using your own camera, you must do all of the calculations again in your own code.
Signature? I ain't signin nuthin!
evilbobthebob
Posts: 10
Joined: Wed Jul 11, 2007 11:03 am
Location: UK

Post by evilbobthebob »

What I need is a 3D model of a gun which attaches to the camera...I am using the standard Irrlicht camera, but the gun just doesn't go where I need it.

It would help if I had an idea of how much the vector3df translates the model.
Bwahahahaha...the world is mine.


Maybe.


Well, maybe not.
evilbobthebob
Posts: 10
Joined: Wed Jul 11, 2007 11:03 am
Location: UK

Post by evilbobthebob »

:oops: Stupid me...the code I wrote does work, it was the model that had the problem. I'll use your function for the HUD, bob
Bwahahahaha...the world is mine.


Maybe.


Well, maybe not.
Post Reply