Shooting in an FPS

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
DanyATK
Posts: 32
Joined: Mon Mar 22, 2004 8:40 pm
Location: Italy
Contact:

Shooting in an FPS

Post by DanyATK »

Hi

I've a serious problem with the shoot part of my game (an FPS).
I don't know how to create a shoot system... that works correctly...
I've tryed many many many many many times, but my code works not correctly ç_ç
How can I create a shoot system (serious and professional) for my FPS?

Please HELP ME
The best italian GM related site
www.gamemaker.it
Tyn
Posts: 932
Joined: Thu Nov 20, 2003 7:53 pm
Location: England
Contact:

Post by Tyn »

Use getSceneNodeFromScreenCoordinatesBB(), then check the distance between the two nodes and if the distance is above the weapon range then no damage is given to the character, you could also put in different damage at certain range if you wanted.
Endar
Posts: 145
Joined: Mon Jun 14, 2004 7:59 am

Post by Endar »

I think a good idea would be to create a weapon class, and all the weapons you have would just be instances of this class.

So, in each you'd have a shoot function which could find if there has been an hit (with getSceneNodeFromScreenCoordinatesBB(), or if a different weapon type, eg. rocket launcher, check if the target is within the radius for splash damage) and return a pointer to the target node if there was a hit.
"The reputation of a thousand years may be determined by the conduct of one hour."
-Japanese Proverb
DanyATK
Posts: 32
Joined: Mon Mar 22, 2004 8:40 pm
Location: Italy
Contact:

Post by DanyATK »

Argh... my english is too bad :(

The problem is not to check the collision between the bullet and target...

I don't know how to shoot! I would create the bullet node at same position of model of my shotgun, and how to move the bullet in same direction of cane of the shotgun...

Thx :wink:
The best italian GM related site
www.gamemaker.it
Tyn
Posts: 932
Joined: Thu Nov 20, 2003 7:53 pm
Location: England
Contact:

Post by Tyn »

Create a billboard or whatever and apply a movement animator to the billboard and define the time it wil take to get there,then have a deletion animator set to the time you enter for the movement and it will move a billboard from the start position to the target, then disappear.
DanyATK
Posts: 32
Joined: Mon Mar 22, 2004 8:40 pm
Location: Italy
Contact:

Post by DanyATK »

I've used this code... but don't work correcly...

Code: Select all

vector3df start = (camera->getPosition());
vector3df end = camera->getTarget() - start;
start = shotgun->getAbsolutePosition();
end.normalize();
end = end * camera->getFarValue();
				
IAnimatedMesh* mesh_bullet = smgr->getMesh("bullet.3ds");
IAnimatedMeshSceneNode* bullet = smgr->addAnimatedMeshSceneNode( mesh_bullet, 0, -1, shotgun->getAbsolutePosition() );
bullet->setMaterialTexture(0, driver->getTexture("texture_bullet.bmp"));
bullet->setMaterialType(EMT_SPHERE_MAP);
bullet->setMaterialFlag(EMF_LIGHTING, true);
ISceneNodeAnimator* anim = 0;
anim = smgr->createFlyStraightAnimator(start, end, 5000, false);
bullet->addAnimator(anim);
anim->drop();
Can anyone post a better code? I would want to obtain the same effect of a commercial FPS...
The best italian GM related site
www.gamemaker.it
timmy
Posts: 34
Joined: Wed Jul 14, 2004 2:48 am

Post by timmy »

your problem seems kind of related to mine http://irrlicht.sourceforge.net/phpBB2/ ... php?t=3268
puh
Posts: 356
Joined: Tue Aug 26, 2003 3:53 pm

Post by puh »

Why don't you want to use irrlicht-0.6\examples\Techdemo\ approach?
DanyATK
Posts: 32
Joined: Mon Mar 22, 2004 8:40 pm
Location: Italy
Contact:

Post by DanyATK »

because the bullet in techdemo has as start point the camera not the weapon model... and if i set as start point the shotgun, code don't work correctly
The best italian GM related site
www.gamemaker.it
Electron
Posts: 874
Joined: Sun Mar 14, 2004 12:05 am
Location: Massachusetts USA

Post by Electron »

This took me a while to get right because of my poor matrix knowledge. Here's what you need to do. Node is the node of your weapon. Range is the maximum distance your weapon will fire

Code: Select all

    matrix4 mat=node->getAbsoluteTransformation();
    vector3df vec=mat.getTranslation();
    matrix4 targetmat;
    targetmat.setTranslation(vector3df(range,0,0));
    targetmat= mat * targetmat;
    line3d<f32> ray(vec, targetmat.getTranslation()); /*set one point to the position of the weapon, the other to the X axis
    note that the line is the maximum length that the weapon can shoot*/
Now you can feed ray to the getSceneNodeFromRayBB function.

Make sure that you've done jox's fixe for the matrix4::operator*
You do a lot of programming? Really? I try to get some in, but the debugging keeps me pretty busy.

Crucible of Stars
Post Reply