First Person

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
Paddon
Posts: 43
Joined: Thu Jul 06, 2006 4:09 pm

First Person

Post by Paddon »

I want to implement a first person gun. Now is there a way to keep track of the camera position and move the weapon accordingly to keep it in front of the camera at the same spot at all times?
- Jeff Paddon
Undergraduate Research Assistant
Physics Department
St. Francis Xavier University
afecelis
Admin
Posts: 3075
Joined: Sun Feb 22, 2004 10:44 pm
Location: Colombia
Contact:

Post by afecelis »

you just said it. You gotta make your gun mesh a child of the camera. Search for it. It's been solved before; with code and everything.
Paddon
Posts: 43
Joined: Thu Jul 06, 2006 4:09 pm

Post by Paddon »

ok I understand what to do but I can't seem to find out how to assign a nod as the child of the camera node. I have been programming for a long time now, though I have only recently been introduced to classes...
- Jeff Paddon
Undergraduate Research Assistant
Physics Department
St. Francis Xavier University
Vuen
Posts: 25
Joined: Tue Jul 11, 2006 8:03 am

Post by Vuen »

stodge
Posts: 216
Joined: Fri Dec 05, 2003 5:57 pm

Post by stodge »

Define a point in your player model called "Eyes". Attach the camera to this. Define a point on your player's hand called "RHand" or something like that. Attach your gun to this.

When your player walks, the camera should be animated automatically based on the "Eyes" node and the gun should also move based on the "RHand" node. You can choose to render the player model or not.

I think this is how Torque does it, and I think it's quite a nice design. Though I'm not an expert!
Paddon
Posts: 43
Joined: Thu Jul 06, 2006 4:09 pm

Post by Paddon »

thanks guys, that was a lot simpler then I intended haha....thats never aa bad thing though
- Jeff Paddon
Undergraduate Research Assistant
Physics Department
St. Francis Xavier University
afecelis
Admin
Posts: 3075
Joined: Sun Feb 22, 2004 10:44 pm
Location: Colombia
Contact:

Post by afecelis »

Code: Select all

//load gun and make it a child of the camera
	scene::IAnimatedMesh* gun = smgr->getMesh("./data/gun.3ds");
	scene::IAnimatedMeshSceneNode* gunnode = smgr->addAnimatedMeshSceneNode(gun);
	gunnode->setParent(camera);
	gunnode->setPosition(core::vector3df(72,-90,90));
	gunnode->setScale( irr::core::vector3df(1,1,1));
	gunnode->setRotation(core::vector3df(0,270,0));
play with the position, rotation and scale values till you get it right.
Post Reply