x


Water sound effects

How do you put a sound on water that is always playing across the surface, not just a singular point?

more ▼

asked Mar 16 '10 at 04:18 PM

Fishman92 gravatar image

Fishman92
2.4k 101 113 128

Great question!

Mar 16 '10 at 05:33 PM duck ♦♦
(comments are locked)
10|3000 characters needed characters left

3 answers: sort voted first

I'm thinking that you could implmenent this by having a separate invisible GameObject in your scene which has an AudioSource attached (with the looped water sound clip assigned).

You'd then move this audiosource around to follow the player, but have it constrained to the shape of your water. The complexity of implementing this would then be directly tied to the complexity of the shape of your water.

For example, the easiest shape would be a circular pond or lake. In this case, you could use something like this pseudo-code to constrain the water audio object:

Vector3 audioPos = playerPos;
audioPos.y = waterPos.y;
// constrain position to circle around water
if ((audioPos  - waterPos).magnitude > waterRadius)
{
    audioPos = waterPos + (audioPos-waterPos).normalized * waterRadius;
}

Similarly, a square or rectangular shaped area of water would be fairly simple:

Vector3 audioPos = playerPos;
audioPos.y = waterPos.y;

// constrain x and z to 2d rectangle around water
audioPos.x = Mathf.Max( waterPos.x - waterWidth*0.5f , audioPos.x);
audioPos.x = Mathf.Min( waterPos.x + waterWidth*0.5f , audioPos.x);
audioPos.z = Mathf.Max( waterPos.z - waterLength*0.5f , audioPos.z);
audioPos.z = Mathf.Min( waterPos.z + waterLength*0.5f , audioPos.z;

If your water is more of an arbitrary shape, you'll need a more complex algorithm to determine how to constrain your audio object to the 2d surface of that shape. Perhaps some code which first finds the triangle in your water mesh which is nearest the player, and then some code which constrains the audio object to that triangle.

If your water is made using a large plane which intersects a terrain which dips below the water level in certain areas (as is a common technique), you'll need another method again, because this set-up doesn't readily reveal any data that you can use to determine the nearest area of water. One method that springs to mind to implement this would be to do a quick "scan" of your whole terrain using raycasts, to build up a low-res 2d grid of data representing "water" and "non-water" areas. Then, at runtime, you could have an algorithm which picks the nearest grid cell marked as water to determine the correct location for your audiosource. You'd also need to add some kind of blending between the positions to avoid the audiosource suddenly jumping from one cell position to another.

Anyway... food for thought, it's definitely an interesting question. Good luck!

more ▼

answered Mar 16 '10 at 05:33 PM

duck gravatar image

duck ♦♦
41k 92 148 415

Nice approach..

Mar 16 '10 at 05:47 PM Lipis

I think what i'll do is just seperate sounds objects along the river all with he same sound... Should prove a little easier. But thanks!.

Mar 17 '10 at 07:49 AM Fishman92

Heh - yes good idea, in fact I was thinking of coming back to this answer and adding the idea of placing numerous audiosources by hand. It's certainly the simplest idea!

Mar 17 '10 at 05:10 PM duck ♦♦
(comments are locked)
10|3000 characters needed characters left

I need this too and i think the most practical way would be to have a sound object follow the player around and stop at the edge of the water. idk how to do this, though. )= maybe a collider?

more ▼

answered May 17 '10 at 01:34 AM

Envy gravatar image

Envy
165 17 18 22

(comments are locked)
10|3000 characters needed characters left

I'm going to answer it.

Make the aer a trigger, attach a sound to the player and make a script so when the player enters the trigger, the sound on the player activates.

more ▼

answered May 17 '10 at 02:49 PM

Fishman92 gravatar image

Fishman92
2.4k 101 113 128

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x523
x300

asked: Mar 16 '10 at 04:18 PM

Seen: 1701 times

Last Updated: Mar 16 '10 at 04:37 PM