Behaviour suggestion - sound proximity to player/actor.

spoogob

  • Posts: 1106
I wanted a behaviour recently, that allowed sounds to be given to an actor, so that when the player is within a certain 'radius', it plays/fades in/out.

(i tried this myself but struggled to get it working correctly - so here it is as a suggestion for 3.0).


Miasmos Games

  • Posts: 878
I'm currently working to get my Stencyl set-up working again so I can actually make stuff :P But I like the sound of this and it doesn't sound too hard, although those could be famous last words. I'll give it a go though, and perhaps it will work.

Cupcake Bounce

spoogob

  • Posts: 1106
:)

The furthest Ive managed to get, is create the behaviour, it checks against the players co-ordinates, and ive set attributes for radius, sound to play, channel etc. when you get within the desired radius, it fades the specific channel in (the sound in theory is already playing when the actor is created - its just quiet .. 0% volume), and when you move away, it decreases the volume.

At the moment, it only 'increases by 1' when you get within its radius, and decreases by 1 when you move outside its radius. (kinda like, a constant up, up up, or down down down.). id like it to hold a value if you stand at a certain distance to an actor, not just decrease or increase. (if you understand what i mean!  ;D )

It does its job at the moment, but it could be that little bit better - but im not quite good enough to fullfill that task!  :'(

Luyren

  • *
  • Posts: 2775
If you know the radius and the distance between the sound source and your actor, you can use these to make a percentage, and use this percentage directly to set the volume of that sound channel (since the volume blocks use percentages, right?).

If Radius is 50, and the distance between the actors is 10, it's 20% of the maximum distance. You just use the remaining percentage (100 - 20 = 80, since the closer you get, the louder the sound) and set the volume (in this case, set volume to 80%).

Is that what you need?
My Stencyl resources are available here: https://luyren.itch.io/
Cutscenes, RPG Elements, Particles, Map System and many more.

spoogob

  • Posts: 1106
Something like that yeah. i mean, it sounds fine as it is, you wouldnt notice too much, but it would be nice if you as the player stopped at x distance from the actor the sound is coming from, it held its current volume. at moment, you get near the actor, it increases the volume until it hits 100.. you leave the radius of the actor and it decreases the volume till it hits 0.

Im struggling with Y co-ordinates at moment. As it is, it fades in/out X when you get near the actor, but for Y, if you go above an amount, it just turns the sound off, and the same below.

Im not the greatest at this stuff, but i try :) Ive managed to create what i need so far, but this one has puzzled me.

Luyren

  • *
  • Posts: 2775
You can use the pythagora theorem (using the x-center of both actors) to find out the distance. This handles your X/Y problem, I think.

You then use this distance to find that percentage I mentioned in the other post. Since you'd be using the "set volume" block, it would only change volume if the actor moves away or towards the sound source, so you wouldn't have to worry about it becoming 100% inside the radius and 0% outside.
My Stencyl resources are available here: https://luyren.itch.io/
Cutscenes, RPG Elements, Particles, Map System and many more.

spoogob

  • Posts: 1106
I kinda understand what your saying, so ill go and see what i can do. will report back when ive failed miserably!  :D

edit: to save adding another post..

failed miserably! just cant seem to get it right. I can get as far as what i created previously - fading in and out when you get near to an actor, but thats about it. I understand the theory behind it, just cant seem to put it into practice.

« Last Edit: August 28, 2012, 09:17:59 am by spoogob »

Luyren

  • *
  • Posts: 2775
Can you attach a screen shot of your behavior?
My Stencyl resources are available here: https://luyren.itch.io/
Cutscenes, RPG Elements, Particles, Map System and many more.

spoogob

  • Posts: 1106
yeah no problem. i didnt get very far with the new version of my behaviour - i managed to check both x and y and then i played around trying to implement what we spoke about, but i struggle sometimes with these kinda things - im more a design/arty/music kinda person, and find programming/logic/thinking hurts sometimes  :D

the attached one is the old one, checks actor x position against you (please excuse if it is on the simple side). when you set the distance (in this case 256- i forgot to implement the distance/radius and must have been setting it manually), it checks and when you get within that distance it basically increases volume or decreases as you leave. it kinda does the job - until you need Y direction!  :(

thanks for the advice anyhow so far. (and thanks to MG also for offering to have a go at it).. hopefully it will work out one way or other.

Luyren

  • *
  • Posts: 2775
This is how I'd do it. I urge you to read it, and ask any questions you may have. It's better if you understand this than just copying the behavior.
My Stencyl resources are available here: https://luyren.itch.io/
Cutscenes, RPG Elements, Particles, Map System and many more.

spoogob

  • Posts: 1106
thanks for that, i will read through it and see if i can work parts of it out, but i already see bits i dont understand so i will get back and ask just what it is doing in those areas.

spoogob

  • Posts: 1106
hi again,

just a quick update. have implemented that into my behaviour and all works fine mostly.

One thing that i haven't worked out is why the final 'stop sound on channel' seems to interfere with my music that is playing on channel 0.. (i set the channel for actors with this behaviour to everything but 0). if i disable that one thing, music plays, and sounds fade in and out very nicely on actors, but enabled it stops my music playing as soon as the scene loads. shall look into it a bit more.

have partially worked out whats happening in the behaviour anyhow, will have a couple of questions soon though.

captaincomic

  • *
  • Posts: 6108
Since this was a behavior suggestion, should we include something like this with the pre-shipped ones?

spoogob

  • Posts: 1106
I would say yes to that.

I think a sound proximity behaviour is great, and wouldnt be without the one I was helped with to create. Is nice to move around your game/scenery and have sounds fade in and out on actors and such.

captaincomic

  • *
  • Posts: 6108
Okay. Luyren, would you mind sharing your behavior so that we can ship it? :)