Argh!

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:

Argh!

Post 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 :evil:)

Shotgun is a child of camera, and it's position not would have to be approximately the same position of camera?

Plese help me :cry: and excuse my bad english
The best italian GM related site
www.gamemaker.it
madinitaly
Posts: 92
Joined: Sat Nov 29, 2003 8:30 pm
Contact:

Post by madinitaly »

Instead of:

Code: Select all

yourShotGunNode->getPosition ();
try using:

Code: Select all

yourShotGunNode->getAbsolutePosition ();
DanyATK
Posts: 32
Joined: Mon Mar 22, 2004 8:40 pm
Location: Italy
Contact:

Post 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?
The best italian GM related site
www.gamemaker.it
DanyATK
Posts: 32
Joined: Mon Mar 22, 2004 8:40 pm
Location: Italy
Contact:

Post by DanyATK »

Nobody can help me? :(
Then... exists some tutorial that explains how to make?

Thanks
The best italian GM related site
www.gamemaker.it
Mafioso

Bullets leaving from the right place

Post 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());
Electron
Posts: 874
Joined: Sun Mar 14, 2004 12:05 am
Location: Massachusetts USA

Post 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.
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