简体   繁体   English

太空射击游戏中的3D音效

[英]3D sound effects in space shooter game

I am trying to implement a 3d sound system for my space shooter game . 我正在尝试为我的太空射击游戏实现3D声音系统。 I have everything ready (playng sound with different volume in each side etc.) but i cant find the corrent formula to calculate the correct volume for each side. 我已经准备好一切(每侧播放不同音量的声音等等),但是我找不到合适的公式来计算每侧的正确音量。

The general idea is that every time the player(ship) kill's an enemie (the cammera is always on the top of the ship) , an explotion will be heard with the correct left and right volume . 通常的想法是,每当玩家杀死一个敌人时(摄像机总是在船的顶部),就会听到正确的左右音量。 So if the enemie is right of the ship then the right channel will be heard more , same with the left case. 因此,如果敌人在飞船的右边,那么与左边的情况一样,会更多地听到右边的频道。

so i have 所以我有

vector ship
vector enemie

and

playSound(left ? ,right ?)

How does game engines calculate the left and right channels? 游戏引擎如何计算左右声道?

Finally i solved it. 终于我解决了。 I used something similar to what Ameoo said. 我使用了类似于Ameoo所说的话。

Here it is: 这里是:

void Play3D(int id,vector3d ship,vector3d pos,float arenaWidth,float power)
{
    float disright=calculate_distance(ship.x+0.2f,ship.y,pos.x,pos.y);
    float disleft=calculate_distance(ship.x-0.2f,ship.y,pos.x,pos.y);
    sf.Play(2,1-disleft/arenaWidth*power,1-disright/arenaWidth*power);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM