Page 1 of 1
Argh!
Posted: Thu Jul 15, 2004 8:54 am
by DanyATK
Hi
I'm creating my fps... now, i'm writing the shot part.
I've an FPS camera and a child shotgun attach to it. I should to calculate the line for the staight animator (bullet's trajectory). When I select as start point the camera position, all work correctly and irrlicht create bullet at same position of camera. but... if I select as start point the shotgun position... irrlicht create the bullet at position 0,0,0... WHYYYYYY (I've controlled the position of shotgun many times and it is NOT 0,0,0
)
Shotgun is a child of camera, and it's position not would have to be approximately the same position of camera?
Plese help me
and excuse my bad english
Posted: Thu Jul 15, 2004 10:04 am
by madinitaly
Instead of:
try using:
Code: Select all
yourShotGunNode->getAbsolutePosition ();
Posted: Thu Jul 15, 2004 1:48 pm
by DanyATK
Using "getAbsolutePosition()" problem is partially resolved... now, irrlicht create bullet at same position of my shotgun... but the bullet dosen't fly in correct direction. I use this code:
Code: Select all
if (shotgun != 0 && event.EventType == EET_MOUSE_INPUT_EVENT &&
event.MouseInput.Event == EMIE_LMOUSE_PRESSED_DOWN)
{
if (ok == 1) {
if (ammo > 0) {
vector3df start = (shotgun->getAbsolutePosition());
vector3df end = (camera->getTarget()-start);
end.normalize();
end = start + (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();
}
}
}
return true;
I think that code is correct but the bullet have a strange trajectory... can anyone help me?
Posted: Fri Jul 16, 2004 10:53 pm
by DanyATK
Nobody can help me?
Then... exists some tutorial that explains how to make?
Thanks
Bullets leaving from the right place
Posted: Sun Aug 22, 2004 5:58 pm
by Mafioso
Man I solved this problem this way:
Code: Select all
vector3df start = gun->getAbsolutePosition();
float xModulus = camera->getTarget().X - camera->getPosition().X;
float yModulus = camera->getTarget().Y - camera->getPosition().Y;
float zModulus = camera->getTarget().Z - camera->getPosition().Z;
vector3df gunTarget = vector3df(gun->getAbsolutePosition().X + xModulus,
gun->getAbsolutePosition().Y + yModulus,
gun->getAbsolutePosition().Z + zModulus);
vector3df end = (gunTarget - start);
end.normalize();
end = start + (end * camera->getFarValue());
Posted: Mon Aug 23, 2004 12:43 pm
by Electron
I ignore the camera in my shooting code, after all I might not always want to shoot where the camera is pointing and I consider it bad form to depend on the camera. Get the transformation matrix of the shotgun. You can create a target vector like this
vector3df(targetDist,0,0) targetVec;
matrix.transformVect(targetVec);
Assuming the x axis is the front of the shotgun (plenty use Z instead) and that the variably matrix holds the absolute transformation of the shotgun. You can now create a line with the shotgun position at one endpt and the transformed targetVec at the other endpt.