Пули игрока идут не в ту сторону, а пули противника не стреляют

Немного серьезное затруднение, поскольку самый большой аспект моей игры, кажется, не функционирует.
Я делаю 3D-игру по захвату космического пространства и пытаюсь заставить игрока (и врагов) стрелять друг в друга. Но ни один из них, похоже, не делает этого.

У меня есть менеджер атаки для обоих, который обрабатывает их код.

/**
* Prepares a bullet for firing if the current time is greater than
*   the last fired time + the firing delay. This purpose of this is to
*   put a delay between each bullet as it is fired.  A bullet is only
*   'readied' for firing if it is available, i.e. it's alive property
*   is set to false.
*
*/
void PlayerAttackManager::fireBullet() {
if ( mCurrentTime > ( mLastFiredTime + sFIRE_DELAY ) ) {
// Find the next available bullet (if one exists)
std::vector<Bullet>::iterator end = mBullets.end();
std::vector<Bullet>::iterator curr = mBullets.begin();
for ( ; curr != end && (*curr).alive() == true; ++curr );

// If there is a bullet available.
if ( curr != end ) {
// Move bullet to firing location and set alive.
Vector3 bulletPos = mSceneMgr->getSceneNode( "PlayerParentNode" )->getPosition();

Vector3 bulletDir = mSceneMgr->getSceneNode( "PlayerParentNode" )->getOrientation() * Vector3::UNIT_Z;
// Pass the initial screen position and direction of travel for the bullet.
(*curr).reset( bulletPos, bulletDir );

}

mLastFiredTime = mCurrentTime;
}
}

Вышеупомянутый метод вызывается каждый раз, когда нажимается пробел, но он посылает одну вражескую пулю с позиции игрока, движущейся вниз, а другую сверху игрока, движущегося вниз.

Враги должны атаковать (один раз в секунду), который вызывается для EnemyAttackManager, чтобы выстрелить из метода main.cpp frameRenderingQueued
Обновление EnemyAttackManager выглядит следующим образом:

void EnemyAttackManager::update(Real const & timeSinceLastFrame, string name)
{
mName = name;
std::vector<Bullet>::iterator end = mBullets.end();
std::vector<Bullet>::iterator curr = mBullets.begin();
for ( ; curr != end && (*curr).alive() == true; ++curr ) {

if ( curr != end ) {
// Move bullet to firing location and set alive.
Vector3 bulletPos = mSceneMgr->getSceneNode( mName + "Node" )->getPosition();

Vector3 bulletDir =mSceneMgr->getSceneNode(mName+ "Node" )->getOrientation() * Vector3::UNIT_Z;
// Pass the initial screen position and direction of travel for the bullet.
(*curr).reset( bulletPos, bulletDir );
(*curr).update(timeSinceLastFrame);
}}
// Add time since last frame.
mCurrentTime += timeSinceLastFrame;
}

А функции обновления и сброса пули:

void Bullet::update( Real const & timeSinceLastFrame ) {
mTtl -= timeSinceLastFrame;
if ( mTtl <= 0 ) {
mNode->setVisible( false );
}
else {
Enemy* enem = new Enemy();
mNode->translate( sMOVE * mDir * timeSinceLastFrame, Node::TS_LOCAL );
// Retrieve a list of possible enemies.
std::vector<Enemy *> enemyVec = enem->getEnemies();
std::vector<Enemy *>::iterator curr = enemyVec.begin();
std::vector<Enemy *>::iterator end = enemyVec.end();
// Check if the ray intersected any of the enemies
for ( ; curr != end && !CollisionManager::instance()->rayIntersects( mNode->getPosition(), 0, (*curr)->meshName(), mDir )
; ++curr );
if ( curr != end ) { // if bullet has collided with an enemy.
//(*curr)->applyDamage();
mTtl = 0;
//JetPack3D::score += 10;
mNode->setVisible( false );
}
//Check the current bullet pos vs. player
}
}void Bullet::reset( Vector3 const & bulletPos, Vector3 const & bulletDir ) {
mNode->setPosition( bulletPos );
mNode->setVisible( true );
mTtl = sLIFE_TIME;
mDir = bulletDir;
// Need to reverse x and z components so bullet fires forward into the scene.
//now need it to fire right?
mDir.z *= -1;
mDir.x *= -1;
}

Итак, мой вопрос: как заставить врагов и игрока стрелять пулями (враги стреляют вообще и игрок в правильном направлении)

0

Решение

Задача ещё не решена.

Другие решения

Других решений пока нет …

По вопросам рекламы ammmcru@yandex.ru
Adblock
detector