Home   Help Search Login Register  

Author Topic: Math Woes  (Read 2670 times)

0 Members and 1 Guest are viewing this topic.

Offline Rommel92

  • Members
  • *
Math Woes
« on: 30 Sep 2009, 09:56:47 »
Oh how I loves these threads :P.

This code below acts as though there is positional sound, as you face the 'radio' its volume increases slightly, and when you face away it decreases. It also increases and decreases proportional to the distance from the radio.

It was a crude attempt at 'say' without objects interfering; and with music.

Code: [Select]
_trackList = ["Track01_Dead_Forest","Track02_Insertion","Track03_First_To_Fight","Track04_Reinforcements","Track05_Warpath","Track06_Abandoned_Battlespace","Track07_Last_Men_Standing","Track08_Harvest_Red",
"Track09_Movement_To_Contact","Track10_Logistics","Track11_Large_Scale_Assault","Track12_The_Movement","Track13_Sharping_Knives","Track14_Close_Quarter_Combat","Track15_Morning_Sortie",
"Track16_Valentine","Track17_Marauder_Song","Track18_Ghost_Waltz","Track19_Debriefing","Track20_Badlands","Track21_Rise_Of_The_Fallen","Track22_Chernarussian_Anthem","Track26_Organ_Works",
"Track27_Killing_Machines","Ambient01_Cold_Wind","Ambient02_Vague_Shapes","Ambient03_Indian_Summer","Ambient04_Electronic_Warfare","Ambient05_Cobalt","Ambient06_Khe_Sanh_Riff",
"Ambient07_Manhattan","Ambient08_Reforger","Short01_Defcon_Three","C2_ND_Ambient"];

while {true} do {
_song = _trackList select floor(random(count _tracklist));
_dur = 45;
_tT = time + _dur;
playmusic _song;
while {_tT > time} do {
_dist = player distance _this;
while {_dist <= 50 and (_tT > time)} do {
sleep 0.1;
_pos1 = getpos _this;
_pos2 = getpos player;
_dir1 = abs(((_pos1 select 0) - (_pos2 select 0)) atan2 ((_pos1 select 1) - (_pos2 select 1)));
_dir2 = getdir player;
if (_dir2 > 180) then {_dir2 = abs(_dir2 - 360)};
_diff = (_dir2 max _dir1) - (_dir2 min _dir1);
_volume = 1 min ((1 / _dist) * ((0.25 max (43 / _diff)) min 1));
0 fademusic _volume;
_dist = player distance _this;
};
0 fademusic 0;
sleep 1;
};
};

It works perfect, except when facing E(90) and W(270) away from the object (pos1) it increases the sound. Whereas it should decrease; this does not occur for N(0) or S(180).

Any help appreciated.

Offline bedges

  • Administrator
  • *****
    • OFPEC The Editing Center
Re: Math Woes
« Reply #1 on: 30 Sep 2009, 12:16:03 »
This might help. Your actual mileage may vary.

Offline Rommel92

  • Members
  • *
Re: Math Woes
« Reply #2 on: 02 Oct 2009, 09:07:48 »
Code: [Select]
_trackList = ["Track01_Dead_Forest","Track02_Insertion","Track03_First_To_Fight","Track04_Reinforcements","Track05_Warpath","Track06_Abandoned_Battlespace","Track07_Last_Men_Standing","Track08_Harvest_Red",
"Track09_Movement_To_Contact","Track10_Logistics","Track11_Large_Scale_Assault","Track12_The_Movement","Track13_Sharping_Knives","Track14_Close_Quarter_Combat","Track15_Morning_Sortie",
"Track16_Valentine","Track17_Marauder_Song","Track18_Ghost_Waltz","Track19_Debriefing","Track20_Badlands","Track21_Rise_Of_The_Fallen","Track22_Chernarussian_Anthem","Track26_Organ_Works",
"Track27_Killing_Machines","Ambient01_Cold_Wind","Ambient02_Vague_Shapes","Ambient03_Indian_Summer","Ambient04_Electronic_Warfare","Ambient05_Cobalt","Ambient06_Khe_Sanh_Riff",
"Ambient07_Manhattan","Ambient08_Reforger","Short01_Defcon_Three","C2_ND_Ambient"];

while {true} do {
_song = _trackList select floor(random(count _tracklist));
_dur = 45;
_tT = time + _dur;
playmusic _song;
while {_tT > time} do {
_dist = player distance _this;
while {_dist <= 50 and (_tT > time)} do {
sleep 0.1;
_pos1 = getpos _this;
_pos2 = getpos player;
_dir1 = ((_pos1 select 0) - (_pos2 select 0)) atan2 ((_pos1 select 1) - (_pos2 select 1));
_dir2 = getdir player;
if (_dir1 < 0) then {_dir1 = 360 + _dir1};
_diff = (_dir2 max _dir1) - (_dir2 min _dir1);
if (_diff > 180) then {_diff = abs(_diff - 360)};
_volume = 1 min ((1 / _dist) * ((0.25 max (43 / _diff)) min 1));
0 fademusic _volume;
_dist = player distance _this;
};
0 fademusic 0;
sleep 1;
};
};

Sorted it!