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.
Bullet help
Why not setting up the position right ???
Add an offset to the received cam position, like this:the values depends on your weapons position...
Add an offset to the received cam position, like this:
Code: Select all
posBullet = cam->getPosition() + vector3df(10, -10, 5);
while(!asleep) sheep++;
IrrExtensions:
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
IrrExtensions:
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
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 !!!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...
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());
BTW, how do you call sin/cos/tan in english ???
In german they're called "Winkelfunktionen", something like angle functions...
while(!asleep) sheep++;
IrrExtensions:
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
IrrExtensions:
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
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 !!!
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:
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
IrrExtensions:
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
-
- Posts: 12
- Joined: Sun Apr 23, 2006 11:05 pm
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
ahhhh
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();
}
I'm not Game Manic