简体   繁体   中英

3D sound effects in space shooter game

I am trying to implement a 3d sound system for my space shooter game . 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.

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);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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