Bullet help

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
Anteater
Posts: 266
Joined: Thu Jun 01, 2006 4:02 pm
Location: Earth
Contact:

Bullet help

Post by Anteater »

Hi. I'm trying to make a bullet appear down and to the left from the FPS players' perspective. Right now it comes from cam->getPosition but that looks lousy. I want it to appear where the gun's muzzle is. I know it has something to do with sin/cos, but I don't know how to go about it.






PS: I looked at the sin/cos topic in the code snippets forum but that didn't help.
Acki
Posts: 3496
Joined: Tue Jun 29, 2004 12:04 am
Location: Nobody's Place (Venlo NL)
Contact:

Post by Acki »

Why not setting up the position right ???
Add an offset to the received cam position, like this:

Code: Select all

posBullet = cam->getPosition() + vector3df(10, -10, 5);
the values depends on your weapons position...
while(!asleep) sheep++;
IrrExtensions:Image
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
Anteater
Posts: 266
Joined: Thu Jun 01, 2006 4:02 pm
Location: Earth
Contact:

Post by Anteater »

That doesn't make the offset relative to the camera's rotation, though. For example, if it was camera->getPosition() + vector3df(10,0,0) it would only work of the Y rotation of the cam was 90 degrees. That's sin/cos is needed.
Acki
Posts: 3496
Joined: Tue Jun 29, 2004 12:04 am
Location: Nobody's Place (Venlo NL)
Contact:

Post by Acki »

Yes, I see...
But you can get around this by adding the bullet as a child of the cam...
This way it has always the same direction (rotation) as the cam...
Then you can get the absolute position/rotation of the bullet and set it as not a cam's child...
I think this way it's also more faster than using sin/cos !!!

Code: Select all

ISceneNode* bullet = smgr->addMeshSceneNode (meshBullet, cam, -1, vector3df(10, -10, 10));
matrix4 mat = bullet->getAbsoluteTransformation();
bullet->setParent(smgr->getRootSceneNode());
bullet->setPosition(mat.getTranslation());
bullet->setRotation(mat.getRotationDegrees());
This is just a solution I'm thinking of not using sin/cos... ;)

BTW, how do you call sin/cos/tan in english ???
In german they're called "Winkelfunktionen", something like angle functions...
while(!asleep) sheep++;
IrrExtensions:Image
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
Anteater
Posts: 266
Joined: Thu Jun 01, 2006 4:02 pm
Location: Earth
Contact:

Post by Anteater »

BTW, how do you call sin/cos/tan in english ???
If I understand your question correctly, the answer is 'trigonometry', also known as simply 'trig'.
Acki
Posts: 3496
Joined: Tue Jun 29, 2004 12:04 am
Location: Nobody's Place (Venlo NL)
Contact:

Post by Acki »

Ahh, thanks !!! :)
It's sometimes preatty confusing, because some words are translated similar to the other language and other translations using words they mean something complete different in the oher language if you translate them word for word... ;)

A little example:
german measles are called "Röteln" in german
but measles itself are called "Masern"
and Masern and Röteln are complete different deseases !!! ;)
while(!asleep) sheep++;
IrrExtensions:Image
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
Evil Game Manic
Posts: 12
Joined: Sun Apr 23, 2006 11:05 pm

Post by Evil Game Manic »

i copied the code word for word and my game will load but then it will say that it will have to close because of a error..
i think that it is that since i put the code to load the mesh in the shoot function, it causes the error
see below

Code: Select all

void game_manager::shoot1()
{
    scene::IAnimatedMesh* bullet = irrSceneManager->getMesh("gfx/bullet.3ds");
    core::vector3df start = camera->getPosition();
    core::vector3df	end = (camera->getTarget() - start);
	end.normalize();
	start += end*5.0f;
	end = start + (end * camera->getFarValue()); 
	
	// bullet
	scene::ISceneNode* bulletnode = 0;
	bulletnode = this->irrSceneManager->addAnimatedMeshSceneNode(bullet,camera,-1,vector3df(10,-10,5));

    matrix4 mat = bulletnode->getAbsoluteTransformation(); 
    bulletnode->setParent(irrSceneManager->getRootSceneNode()); 
    bulletnode->setPosition(mat.getTranslation()); 
    bulletnode->setRotation(mat.getRotationDegrees()); 
		
	f32 length = (f32)(end - start).getLength();
	const f32 speed = 0.6f;
	u32 time = (u32)(length / speed);

	scene::ISceneNodeAnimator* anim = 0;

	// set flight line

	anim = this->irrSceneManager->createFlyStraightAnimator(start, end, time);
	bulletnode->addAnimator(anim);	
	anim->drop();

	anim = this->irrSceneManager->createDeleteAnimator(time);
	bulletnode->addAnimator(anim);
	anim->drop();
}
ahhhh :evil:
I'm not Game Manic
Post Reply