• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[Solved] Play sound while moving

Status
Not open for further replies.
Level 4
Joined
Dec 14, 2016
Messages
47
Howdy y'all! I need a lil help about somethin'.

So I'm making a space map that's near completion, but this problem is keepin' me from progressing. I want all units play a certain looping sound while moving.

The units of this map are all spaceships, so I kinda want them to make engine sounds as they move. Of course, different unit type play different move sound depending on my taste (for example, massive spaceships use different move sound than smaller spaceships).

I tried some of the methods which it didn't worked out as I wanted to.

Method 1: Play Sound from Sound editor (didn't work)
As we know it, we can't play a sound file from Sound Editor without finishing or stopping the same sound that is currently played.

Method 2: Use a dummy model as "sound" (so close)
I had this brilliant idea that when moving, periodically creates a special effect using a "dummy model" that I created from Mago's Model Editor. This model plays a certain sound when it plays its Death animation. So in a sense, it "plays" a sound when a unit moves. Problem is, I can't control when to stop playing a sound. For example, I used "DoomTarget" sound which lasts for 2 seconds. If a unit moved for 1 second, the sound still plays until it is finished.

I've no idea now how to achieve this feature. Not really necessary to accomplish the map, but it'll be great if I make this one a lil bit realistic. That's why I need help right now.

Any ideas?
 
Last edited:
Level 4
Joined
Dec 14, 2016
Messages
47
Method 1 is possible. You need to play a 3D sound emitting from the ship. You can attach sounds to units.
No, they don't work well when played simultaneously. I tried playing them, but only one unit has the sound attached to it. I think it will work if I create many sound variables from Sound Editor and attach it to every single unit, but I won't consider that one.
 
Level 4
Joined
Dec 14, 2016
Messages
47
You can also try and edit the models, add event objects that play sounds that are barely used and replace those sounds with the sounds you want.
I forgot to include this one in the thread that this was my method 3, which it didn't work. I place the event object in the Walk animation. It did play the sound, but it does not loop.
 
Level 38
Joined
Feb 27, 2007
Messages
4,951
No, they don't work well when played simultaneously. I tried playing them, but only one unit has the sound attached to it.
That's because the 'sounds' you play in GUI are actually global variables that you place in a particular location. They are instanced because they are a single object. It's possible to make new copies of the sound variable, which would allow you to play it simultaneously yes. GUI will not let you do this.

For a brute-force manual approach you should use Is Unit Moving 2.1.0.0. I looked through every ability in the editor for ones that by default use the Effect Sound (Looping) field in their data or their buffs' data. These abilities might be able to constantly play a looped 3D sound at a relevant location on the map:
  1. Mana Flare
  2. Mana Regeneration (Neutral)
  3. Locust Swarm
  4. a variety of spells that disable or alter the target in some way like Aerial Shackles and Banish
  5. a few AoE channeled spells like Volcano, Rain of Fire, and Tranquility
  6. the Tornado's timed life buff
Of those, 5 & 6 are out because they have a finite duration and can't be moved without breaking the loop. 4 is probably mostly out of the question unless you cast the relevant spell on an invisible locusted dummy unit that shadows the real ship. 1 requires the caster to channel in a stationary location and the player cannot issue orders to it (but the unit can be moved with triggers), but actually has explicit toggle orders and thus can probably be toggled off while stunned. 2 is bugged to only ever play the default sound effect no matter what you replace it with (maybe manually overwriting the file with an import would work though and I didn't try that) and would at any rate probably only work on units with mana that isn't full 100.00%.

That leaves you with just 3, Locust Swarm. It can be toggled on and off if given 0 duration and cooldown, doesn't leave a green box on the command card while active, and doesn't have to interact with any other units. Cool. It can't be toggled off while silenced or stunned and it will interrupt the unit's current order to do so (though that could be overcome). It does work beautifully for creating sounds on the map, though. Sounds to me like it would work better on an invisible locusted dummy unit that shadows the real ship... and then you probably should just have used banish something else to create the effect in the first place.

Not completely sure on this one but: stopping the loop via toggling off the relevant ability does seem to fade out the looping sound rather than wait for the current loop to end.
 
Last edited:
I forgot to include this one in the thread that this was my method 3, which it didn't work. I place the event object in the Walk animation. It did play the sound, but it does not loop.
Did you also put in the right keyframe for the event object that corresponds to the animation sequence?
 

Uncle

Warcraft Moderator
Level 63
Joined
Aug 10, 2018
Messages
6,457
vJASS:
function AttachSoundUnit takes unit u, string s, integer volume, integer channel, integer duration, boolean doesLoop,boolean stopoutofrange, integer FadeIn, integer FadeOut returns nothing
    set udg_lastCreatedSound = CreateSound (s, doesLoop, true, stopoutofrange, FadeIn, FadeOut, "DefaultEAXON")
    call SetSoundDuration(udg_lastCreatedSound, duration)
    call SetSoundChannel(udg_lastCreatedSound, channel)
    call SetSoundVolume(udg_lastCreatedSound, volume)
    call SetSoundPitch(udg_lastCreatedSound, 1.0)
    call SetSoundDistances(udg_lastCreatedSound, FadeIn, FadeOut)
    call SetSoundDistanceCutoff(udg_lastCreatedSound, FadeOut * .75)
    call SetSoundConeAngles(udg_lastCreatedSound, 0.0, 0.0, volume)
    call SetSoundConeOrientation(udg_lastCreatedSound, 0.0 , 0.0 , 0.0)
    call AttachSoundToUnit(udg_lastCreatedSound, u)
    call StartSound(udg_lastCreatedSound)
endfunction
I assume duration is supposed to be a real. Also, volume ranges from 0 to 127.
 
Last edited:
Level 4
Joined
Dec 14, 2016
Messages
47
That's because the 'sounds' you play in GUI are actually global variables that you place in a particular location. They are instanced because they are a single object. It's possible to make new copies of the sound variable, which would allow you to play it simultaneously yes. GUI will not let you do this.

For a brute-force manual approach you should use Is Unit Moving 2.1.0.0. I looked through every ability in the editor for ones that by default use the Effect Sound (Looping) field in their data or their buffs' data. These abilities might be able to constantly play a looped 3D sound at a relevant location on the map:
  1. Mana Flare
  2. Mana Regeneration (Neutral)
  3. Locust Swarm
  4. a variety of spells that disable or alter the target in some way like Aerial Shackles and Banish
  5. a few AoE channeled spells like Volcano, Rain of Fire, and Tranquility
  6. the Tornado's timed life buff
Of those, 5 & 6 are out because they have a finite duration and can't be moved without breaking the loop. 4 is probably mostly out of the question unless you cast the relevant spell on an invisible locusted dummy unit that shadows the real ship. 1 requires the caster to channel in a stationary location and the player cannot issue orders to it (but the unit can be moved with triggers), but actually has explicit toggle orders and thus can probably be toggled off while stunned. 2 is bugged to only ever play the default sound effect no matter what you replace it with (maybe manually overwriting the file with an import would work though and I didn't try that) and would at any rate probably only work on units with mana that isn't full 100.00%.

That leaves you with just 3, Locust Swarm. It can be toggled on and off if given 0 duration and cooldown, doesn't leave a green box on the command card while active, and doesn't have to interact with any other units. Cool. It can't be toggled off while silenced or stunned and it will interrupt the unit's current order to do so (though that could be overcome). It does work beautifully for creating sounds on the map, though. Sounds to me like it would work better on an invisible locusted dummy unit that shadows the real ship... and then you probably should just have used banish something else to create the effect in the first place.

Not completely sure on this one but: stopping the loop via toggling off the relevant ability does seem to fade out the looping sound rather than wait for the current loop to end.
This is brilliant! I used Mana Flare as the one that plays the walk sound and place it to the locusted dummy unit which is attached to some of the ships after they were built. I used Hashtable to make the created dummy unit unique to every ship and move them instantly periodically to their attached ship. And using the system you suggested, the dummy unit will cast mana flare if the ship is moving and stop if it's not. It worked exactly what I've expected!
Though it will double the number of actual units in the map, it'll be fine as long as the frame rate stays the same and doesn't affect the game performance. Of course, these dummy units will be cleared when the ship is destroyed.
 
Level 4
Joined
Dec 14, 2016
Messages
47
function AttachSoundUnit takes unit u, string s, integer volume, integer channel, integer duration, boolean doesLoop,boolean stopoutofrange, integer FadeIn, integer FadeOut returns nothing set udg_lastCreatedSound = CreateSound (s, doesLoop, true, stopoutofrange, FadeIn, FadeOut, "DefaultEAXON") call SetSoundDuration(udg_lastCreatedSound, duration) call SetSoundChannel(udg_lastCreatedSound, channel) call SetSoundVolume(udg_lastCreatedSound, volume) call SetSoundPitch(udg_lastCreatedSound, 1.0) call SetSoundDistances(udg_lastCreatedSound, FadeIn, FadeOut) call SetSoundDistanceCutoff(udg_lastCreatedSound, FadeOut * .75) call SetSoundConeAngles(udg_lastCreatedSound, 0.0, 0.0, volume) call SetSoundConeOrientation(udg_lastCreatedSound, 0.0 , 0.0 , 0.0) call AttachSoundToUnit(udg_lastCreatedSound, u) call StartSound(udg_lastCreatedSound) endfunction
This is like a revolutionary discovery to me! All I thought I can never create multiple instances of sounds. But with this, I can even edit the pitch and volume of it. I don't know how to make the sound fade out after stopping, though. But anyway, I can make use of this function.

I assume duration is supposed to be a real. Also, volume ranges from 0 to 127.
No, it is indeed an integer value. The one in the GUI function used the real value to adjust the volume percentage, which is a real value.

All in all, I solved the issue by mixing the ideas of those who replied here. Thanks y'all!
I'll label this thread as solved!
 
Status
Not open for further replies.
Top