The Daily Click ::. Forums ::. Klik Coding Help ::. Sounds effects activated by proximity
 

Post Reply  Post Oekaki 
 

Posted By Message

Jess Bowers

Cake > Pie

Registered
  09/01/2009
Points
  310

Has Donated, Thank You!GOTM FEB - 2010 - WINNER!GOTW Winner!
11th January, 2010 at 16:24:18 -

Is there a way to activate a sound effect by proximity to your sprite? You know, the closer the sprite is to the object the louder the sound becomes. And, when the object is far enough away, deactivate the sound altogether.

I'd like to add some ambient sounds to our game. Thanks!

 

OMC

What a goofball

Registered
  21/05/2007
Points
  3516

KlikCast Musician! Guy with a HatSomewhat CrazyARGH SignLikes TDCHas Donated, Thank You!Retired Admin
11th January, 2010 at 16:33:31 -

Use the distance formula! Let's say we have George and Bob.

Whenever the sample is playing:

Set Sample Volume to max hearing distance (the farthest you can be from the source and still hear the sound) minus

Sqr((X( "Bob" )-X( "George" ))*(X( "Bob" )-X( "George" ))-(Y( "Bob" )-Y( "George" ))*(Y( "Bob" )-Y( "George" )))

divided by whatever coefficient you want that equates the max hearing distance with 100. (e.g., without a coefficient, the volume will be loudest when the objects are directly over each other, and silent when they are more than 100 pixels apart.

You can use the compare two general values condition and that formula to determine if the object is in range, rather than having the sample play constantly. For example,

Sqr((X( "Bob" )-X( "George" ))*(X( "Bob" )-X( "George" ))-(Y( "Bob" )-Y( "George" ))*(Y( "Bob" )-Y( "George" ))) Is less than 200, play sample.

Hope that helps!

Edited by OMC

 

  		
  		

Jess Bowers

Cake > Pie

Registered
  09/01/2009
Points
  310

Has Donated, Thank You!GOTM FEB - 2010 - WINNER!GOTW Winner!
11th January, 2010 at 18:59:23 -

OMC to the rescue! Thanks for responding.

That said, I've had some trouble implementing your recommendation. I'm sure my problems are with my own botched implementation but I thought I'd show you the issues I'm having. It appears that above and below my target object (which generates the sound), there are areas that cause the equation to act a little strange.

Here's my example: http://toadstool.net/games/plokey/misc/SoundTest.mfa

What am I doing wrong? Thanks!

 

OMC

What a goofball

Registered
  21/05/2007
Points
  3516

KlikCast Musician! Guy with a HatSomewhat CrazyARGH SignLikes TDCHas Donated, Thank You!Retired Admin
11th January, 2010 at 19:06:39 -

Whoops, that was completely my bad! It's:

Sqr((X( "Bob" )-X( "George" ))*(X( "Bob" )-X( "George" ))+(Y( "Bob" )-Y( "George" ))*(Y( "Bob" )-Y( "George" )))

With an addition sign rather than a subtraction sign between the last X Position and first Y Position.

Edited by OMC

 

  		
  		

Jess Bowers

Cake > Pie

Registered
  09/01/2009
Points
  310

Has Donated, Thank You!GOTM FEB - 2010 - WINNER!GOTW Winner!
11th January, 2010 at 19:11:58 -

Dang you, Clayton!

Seriously, thanks a TON! Worked like a charm.

 

OMC

What a goofball

Registered
  21/05/2007
Points
  3516

KlikCast Musician! Guy with a HatSomewhat CrazyARGH SignLikes TDCHas Donated, Thank You!Retired Admin
11th January, 2010 at 19:15:05 -

Fantastic! I was worried I wouldn't be able to reply. My browser's cookies decided to crumble.

 

  		
  		

Ski

TDC is my stress ball

Registered
  13/03/2005
Points
  10130

GOTW WINNER CUP 1!GOTW WINNER CUP 2!GOTW WINNER CUP 3!KlikCast HelperVIP MemberWii OwnerStrawberryPicture Me This Round 28 Winner!PS3 OwnerI am an April Fool
Candy Cane
11th January, 2010 at 20:11:02 -

Or you could use the Advanced direction object to compare the distances? ?

 
n/a

Jess Bowers

Cake > Pie

Registered
  09/01/2009
Points
  310

Has Donated, Thank You!GOTM FEB - 2010 - WINNER!GOTW Winner!
11th January, 2010 at 21:04:51 -

I've never used the Advanced Direction Object.

OMC, is there a way to make this work with multiple objects of the same type? I'm updated the MFA with the correct equation and added another object:

http://toadstool.net/games/plokey/misc/SoundTest.mfa

 

OMC

What a goofball

Registered
  21/05/2007
Points
  3516

KlikCast Musician! Guy with a HatSomewhat CrazyARGH SignLikes TDCHas Donated, Thank You!Retired Admin
11th January, 2010 at 22:55:17 -

Well I just spent a good chunk of time (almost 2 hours, it looks like. ) trying to get a fastloop system going, but those have never been very successful from me. You'll have to ask someone who's good with fastloops (Or conceivably a different system altogether).

Edited by OMC

 

  		
  		

Silveraura

God's God

Registered
  08/08/2002
Points
  6747

Game of the Week WinnerKlikCast StarAlien In Training!VIP Member360 OwnerWii OwnerSonic SpeedThe Cake is a LieComputerChristmas Tree!
I am an April Fool
11th January, 2010 at 23:15:50 -


Originally Posted by -Adam-
Or you could use the Advanced direction object to compare the distances? ?



Or you could learn the math involved with it so it helps you in the long run. Most extensions are like calculators. They make your life easier by cutting the process down, but don't rely on them without knowing how they work.


Originally Posted by Jess Bowers
I've never used the Advanced Direction Object.

OMC, is there a way to make this work with multiple objects of the same type? I'm updated the MFA with the correct equation and added another object:



With the help of a friend, we were able to create a solid system that did exactly what you're looking for. I used it for the waterfalls in ArcaneTale so that get louder as you approach them and software as you get further from them. There are more multiple waterfalls.

The system works by giving each waterfall a very high value such as 10,000 and then subtracting away from that value, the distance that it is from the player. Then a fastloop event checks each object to see who has the highest value and then uses that objects distance to determine how loud it is.

It works even with two objects of equal distance because even if it has to flip back and forth between both objects, they're the same distance apart, so it doesn't mater since the sound is the same loudness. If you're trying to do channeling (left and right) however, that's a completely different story, and a problem we never quite sorted out due to lack of interest after so long.

Edited by Silveraura

 
http://www.facebook.com/truediamondgame

OMC

What a goofball

Registered
  21/05/2007
Points
  3516

KlikCast Musician! Guy with a HatSomewhat CrazyARGH SignLikes TDCHas Donated, Thank You!Retired Admin
11th January, 2010 at 23:26:21 -


Originally Posted by SiLVERFIRE
The system works by giving each waterfall a very high value such as 10,000 and then subtracting away from that value, the distance that it is from the player. Then a fastloop event checks each object to see who has the highest value and then uses that objects distance to determine how loud it is.



I would love to see an example of the system.

 

  		
  		
   

Post Reply



 



Advertisement

Worth A Click