Rommel 2 Posted September 30, 2009 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. _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. Share this post Link to post Share on other sites
vmaclan 10 Posted October 1, 2009 Maybe as you walk towards the sound you could turn the volume up on your speakers and as you walk away turn it down :D A6-Intruder VMA Share this post Link to post Share on other sites
nichevo 2 Posted October 2, 2009 I normally wouldn't post on a question like this because I'm a meddler at best when it comes to geometry. But since there's no other replies... You seem to be using atan2 correctly, so I wonder, is this possibly because ArmA 2 uses a different co-ordinate system to Cartesian? To elaborate, in Cartesian coordinates the origin is in the "bottom left" and y increases going "up". But to many computer programmers the origin is the "top left" and y increases going "down" (a throwback to how old CRTs worked, I believe). If ArmA 2's coordinate system is "flipped" like this it might be rogering your maths. Perhaps you should try flipping your delta y? I can't say for sure whether my idea matches the symptoms you describe. Don't be surprised if I'm totally off track. Share this post Link to post Share on other sites
Rommel 2 Posted October 2, 2009 (edited) This does not appear to be the case. The fault lies in my modification of the angles. As you can see atan2 returns a direction in positive or negative 180 degrees. :confused: I can turn the 360degree direction to a positive or negative 180 degrees by using this: if (_dir2 > 180) then {_dir2 = abs(_dir2 - 360)}; or reverse it by doing this if (_dir1 < 0) then {_dir1 = 360 + _dir1}; However its the difference of the two angles that I want; and as 360 == 0, my problem becomes very frustrating, because the difference between 355 and 5 is not 350, but 10!!! I almost need to do calculations and differentiate those. edit: The suggestion I made to myself worked. _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; }; }; Well, theres a finished product. Mono-positional sound with music. :) Edited October 2, 2009 by Rommel Share this post Link to post Share on other sites
dale0404 5 Posted October 2, 2009 My head hurts now but this is proper cool! Share this post Link to post Share on other sites