Page 1 of 1

Apply a translation

Posted: Fri Sep 01, 2006 10:47 am
by goutbouyo
Hi,

For my shooting function, I'd like that the bullet start at the right hand of my enemy.
But I don't know how to do that, how can I make a translation ???

Can you help me please, it's only maths...

Posted: Fri Sep 01, 2006 11:11 am
by Xaron
Hi,

I do it that way:

First you need the target vector:

Code: Select all

// Set target vector for the weapon
core::matrix4 rotMatrix;
rotMatrix.setRotationDegrees( player->getRotation() );
core::vector3df targetVec = core::vector3df( 0.0f, 0.0f, 1.0f );
rotMatrix.transformVect( targetVec );
Second: You update your bullet's position with this vector (which you have to store once in your bullet class):

Code: Select all

position += targetVec * static_cast< float >( velocity * timeDiff ) / 1000.0f;
node->setPosition( position );
Regards - Xaron

Posted: Fri Sep 01, 2006 11:27 am
by goutbouyo
Thanks but I'm not sure you understood my problem.
Instead of starting at the ennemy->getPosition(), I want the bullet to start at the right hand of the ennemy.

So how can I do that pease ???

Posted: Fri Sep 01, 2006 11:46 am
by Xaron
The same way. Just get the absolute rotation of the weapon to compute the target vector. Then you start the bullet from the absolute position of the weapon and add this target vector (multiplied with its velocity) every frame to the current bullet position.

Regards - Xaron

Posted: Fri Sep 01, 2006 11:53 am
by goutbouyo
But the problem is that I don't have the position of the enemy's weapon.
And I use an animator for my bullets.

The thing I search is how to find the position of the right hand of the enemy ...

Posted: Fri Sep 01, 2006 12:05 pm
by Xaron
goutbouyo wrote:But the problem is that I don't have the position of the enemy's weapon.
:shock: How come? If you display the enemy including the weapon you have the enemy's scene node. If the weapon is a child of the enemy (this makes things much easier), you can simply get the weapon's position, too. Or is the enemy including the weapon one mesh/model? If yes you still have the relative position of the weapon, haven't you?

Regards - Xaron

Posted: Fri Sep 01, 2006 6:03 pm
by goutbouyo
The weapon is integrated in the enemy model(a MD2).
So, how can I have it position ???

Posted: Mon Sep 04, 2006 6:39 pm
by goutbouyo
No idea on this problem ???

Posted: Tue Sep 05, 2006 12:54 pm
by IPv6
Vfy be you should use joints? it is possible to put joints in model editor that will be moved with the animation. and it is possible to get posishion of specific joint in the animated mesh. just add joints to weapons and get thier positions at runtime

Posted: Tue Sep 05, 2006 10:52 pm
by funcdoobiest
Goutbouyo, you could always just use some trial and error, if you are using the MD2 models I assume you will have some sort of 'firing' animation, so the weapon will always be in the same position relative to the model's position in the world (like Xaron said), so you could just make a reasonable guess and then keep adjusting it until it is right.

I know this isn't a very pleasing solution (the offset could be different for each model) but as far as I know there are no bones you can use in an MD2 model (they use vertex animation, not skeletal) to find the gun position.

Posted: Wed Sep 06, 2006 9:26 am
by goutbouyo
I found a solution :
I create an invisible child node of my enemy's node on his left hand.
Then, I use the absolute position of this node to place my bullet start position.

Thanks all for your help !!!