Page 1 of 1

Shooting in an FPS

Posted: Wed Jul 21, 2004 6:49 pm
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

Posted: Wed Jul 21, 2004 10:55 pm
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.

Posted: Thu Jul 22, 2004 8:15 am
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.

Posted: Thu Jul 22, 2004 6:27 pm
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:

Posted: Thu Jul 22, 2004 6:42 pm
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.

Posted: Thu Jul 22, 2004 10:46 pm
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...

Posted: Thu Jul 22, 2004 11:36 pm
by timmy
your problem seems kind of related to mine http://irrlicht.sourceforge.net/phpBB2/ ... php?t=3268

Posted: Fri Jul 23, 2004 8:00 am
by puh
Why don't you want to use irrlicht-0.6\examples\Techdemo\ approach?

Posted: Fri Jul 23, 2004 2:06 pm
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

Posted: Sun Jul 25, 2004 2:10 pm
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*