Public Group

# Tank bullet Firing from Canon

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

## 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
// 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]

1. 1
Rutin
38
2. 2
3. 3
4. 4
5. 5

• 12
• 15
• 12
• 14
• 9
• ### Forum Statistics

• Total Topics
633354
• Total Posts
3011493
• ### Who's Online (See full list)

There are no registered users currently online

×