How to shot a projectile ???

M@gg!

16-08-2006 14:29:51

I want to shot a projectile. I have the position of creation and the direction in which it shall fly.

[edit:] The direction is the direction of the character and a quaternion.

How do I realise it the best way?

Best regards,
M@gg!

mnm23

16-08-2006 18:05:35

This is how i do it. I get the position and orientation i want to shoot from. Then i get the direction i want it to go. In my code it looks like this.


void Projectiles::shoot(Ogre::Vector3 pos, Ogre::Quaternion ori, Ogre::Vector3 dir, float power)
{

this->mBody->setPositionOrientation( pos, ori );

// this is a standard callback that simply add a gravitational force (-9.8*mass) to the body.
//body->setStandardForceCallback();

// set the initial orientation and velocity!
this->mBody->setPositionOrientation( pos, ori );
this->mBody->setVelocity( (dir * power) );

}



And when i want to call it in my player class (class the projection is associated with) it looks like this.


void PlayerState::shootProj(float power)
{

this->mCurrState = SHOOT;

if(mAnimated)
this->mAb->blend( "Attack1", AnimationBlender::BlendWhileAnimating, 0.3, false );

this->mProjs[mRound]->getSceneNode()->setVisible(true);
this->mProjs[mRound]->shoot(this->getSceneNode()->getPosition() + Vector3(0,1,-1), this->getSceneNode()->getOrientation(),this->getSceneNode()->getOrientation() * this->mLookAt, power);
this->mProjs[mRound]->getBody()->unFreeze();
mRound++;
if(mRound == 5)
mRound = 0;

}


Then in my world class i call shootProj if a key is pressed. You dont need a lot of the stuff i have there its something i was doing in my project. Also this ccode is based on an older project when i was using ogreNewt. The this->mProjs[mRound]-> is so i can call the same sceneNode more than once. But you can get the idea by the line that has this->mProjs[mRound]->shoot. Hope this helps.

M@gg!

16-08-2006 19:10:23

First setting the direction and than shooting is indead a good idea, but why do you set it twice?

mnm23

16-08-2006 19:17:14

Yeah in that first set of code you dont need it. I was looking at an older code i took it out of the newer one. Sorry about that.

M@gg!

17-08-2006 11:03:40

Now the projectiles are fired, but I a recognised a strange behavior.

I use for each projectile a fixed force and postion, but not each projectile is fired the same way. Sometimes they fly definitly shorter.

Does anybody know why?

vec3

17-08-2006 21:54:31

You might want to look at this thread. Could be the problem of not having fixed framerates.

M@gg!

17-08-2006 22:23:46

The thread is indead interresting, but I worry not related to my problem.

I apply the force just only ones and not over the time.

mnm23

18-08-2006 02:46:28

Hey M@gg,

Do you set the force everytime you shoot, because i had the similar problem when i was working on my other project. I set the force of 50 every time i pressed the space bar. Hopefully this helps you.