Jump to content
  • Advertisement
Sign in to follow this  
Prog101

Tank bullet Firing from Canon

This topic is 4254 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Using DX9 and c++, my bullet is not firing directly from my canon? as shown below the green line is the direction it fires To set my tank tower relative to the tank base i multiply the Tank base matrix by the tank tower matrix to get the final Matrix for this object. To set my tank canon relative to the tank tower i multiply the Tank tower matrix by the tank canon matrix to get the final Matrix for this object. it seems to have something to do with setting the velocity // Calc the Initial velocity D3DXVECTOR3 initialVel; initialVel.x = fBulletSpeed * horizontalFactor; initialVel.z = fBulletSpeed * horizontalFactor; initialVel.y = fBulletSpeed * verticalFactor; // Set Initial velocity to the bullet pBullet->setVelocity(initialVel); Game.cpp
void Game::createBullet()
{
	if (IsTimeToFire())
	{	
		Bullet *pBullet = NULL;
		pBullet = new Bullet();
// Set the bullet Relative to the tank cannon
		pBullet->init(pTankCannon->finalMatrix);
// Scale the bullet
		pBullet->setSize(0.5f);				
// Create the bullet
		pBullet->create(dxMgr.pd3dDevice);	
// Add the Bullet to the Bullet List 		
                pBulletList.push_back(pBullet);				
// Place the bullet at the Tank canon position
		pBullet->setPosition(D3DXVECTOR3(0.0f,0.0f,0.0f));	
// Add the Bullet to the in-game objects list to be rendered
		objects.push_back((CGameObject*)pBullet);					
		
		float fBulletSpeed = 2.0f;    // Set the bullets properties
		pBullet->fGravity = -0.098f;
		pBullet->fWindforce = 0.00f;
		
		float fAngleToFire = -pTankCannon->fAngle; // Set the angle to fire
		float verticalFactor = sin(D3DXToRadian(fAngleToFire));
		float horizontalFactor = cos(D3DXToRadian(fAngleToFire));
// Calc the Initial velocity
		D3DXVECTOR3 initialVel;
                initialVel.x = fBulletSpeed * horizontalFactor;
		initialVel.z = fBulletSpeed * horizontalFactor;
		initialVel.y = fBulletSpeed * verticalFactor;
// Set Initial velocity to the bullet
		pBullet->setVelocity(initialVel);
	}
}	


[Edited by - Prog101 on January 31, 2007 9:02:03 AM]

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!