Quantcast
Channel: GameDev.net
Viewing all articles
Browse latest Browse all 17825

[Vector Distance]Trying to get the distance between two vectors and get the enemy to shoot when i'm in range but I can't get it through. Help please

$
0
0
float CalculateDistance(D3DXVECTOR3 enemyPos, D3DXVECTOR3 playerPos) { float length; float distanceX; float distanceZ; distanceX = enemyPos.x - playerPos.x; distanceZ = enemyPos.z - playerPos.z; length = sqrt((distanceX*distanceX) + (distanceZ * distanceZ)); return length; } //And then in my Update D3DXVECTOR3 distance = D3DXVECTOR3(10.0f, 0.0f, 10.0f); if (distance.x || distance.z <= CalculateDistance(D3DXVECTOR3(position.x, 0.0f, position.z), D3DXVECTOR3(CGame::GetPlayer()->GetPos().x, 0.0f, CGame::GetPlayer()->GetPos().z))) { int Random = rand() % 50; if (Random == 0) { D3DXVECTOR3 towardsPlayer = CGame::GetPlayer()->GetPos() - position; Bullet::CreateBullet((D3DXVECTOR3(position.x, position.y - 5.0f, position.z)), D3DXVECTOR3(10.0f, 10.0f, 0.0f), 25.0f, towardsPlayer, 30, BULLET_TYPE_ENEMY); } } I've tried doing this. The enemy continues to shoot even if I'm farther than distance.x and distance.z. Can someone tell me what's wrong?

Viewing all articles
Browse latest Browse all 17825

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>