Jump to content
A 2021 backup has been restored. Forums are closed and work in progress. Join our Discord server for more updates! ×
SoaH City Message Board

[MMF2] Distanced Based Volum Control (Solved!)


Recommended Posts

Distanced Based Volum Control

I was wondering how to get samples a certain volume in MMF2 since I'm quite sick and tired of hearing sounds loop over and over again in some Fan_Games.

So, I thought I'd try to make it as loud as you are from it, Which makes sense in reality really.

My current attampt is the following

Set volume of sample SkidRhinoFix X("Player")+X("EnemyMask")

Any help will be much appreciated and reped.

Link to comment
Share on other sites

My current attampt is the following

Set volume of sample SkidRhinoFix X("Player")+X("EnemyMask")

Seems like that'd make the noise get infinitely loud (IE: Player is at x=35, enemy is at x=60, so 90. Later, you're at x=100, enemy is still at x=60, so 160. And so on).

If I understand what you're saying (noises get louder when you're close, softer when you're far away), try something like this...

--------------------------

While (Absolute Value of(PlayerX - EnemyX) is < 100

***Set Sound Effect volume to (Absolute Value of (PlayerX - EnemyX))

----------------------------

Of course, if you want a greater or less distance for the sound to cover, divide or multiply (PlayerX - EnemyX). IE: If you want the sound to play within 50 pixels of each other instead of 100, multiply by 2.

Link to comment
Share on other sites

I think Larks did something like that for me a while back. I don't use MMF2 anymore. Construct can do this with ease. Anyway, I'll try to do something for you when I get home from school.

Okay, Thanks Azu.

Seems like that'd make the noise get infinitely loud (IE: Player is at x=35, enemy is at x=60, so 90. Later, you're at x=100, enemy is still at x=60, so 160. And so on).

If I understand what you're saying (noises get louder when you're close, softer when you're far away), try something like this...

--------------------------

While (Absolute Value of(PlayerX - EnemyX) is > 100

***Set Sound Effect volume to (Absolute Value of (PlayerX - EnemyX))

----------------------------

Of course, if you want a greater or less distance for the sound to cover, divide or multiply (PlayerX - EnemyX). IE: If you want the sound to play within 50 pixels of each other instead of 100, multiply by 2.

absvolumedistance.png

This doesn't seem to work USC :/.

Link to comment
Share on other sites

Distance = Sqrt((Xsound - Xcamera)^2 + (Ysound - Ycamera)^2)
Volume = 100 - Min(Distance/SoundFalloffDistance*100, 100)

Where:
- Volume = Volume of the sample
- Distance = Distance from the camera/player to the sound emitter. Just the basic pythagoras formula.
- SoundFalloffDistance = Maxium distance at wich the sound can be heard

Link to comment
Share on other sites

Camera = player; sound = enemy.

-----------------------

Hmm...What exactly happens when you run my code? Can you do me a favor and put (Absolute Value (PlayerX - EnemyX)) into a counter, so you can see what happens to that value as Sonic gets closer?

Link to comment
Share on other sites

What does Sqrt Mean?

Edit: The numeber decreases and increases as the rhino passed through you from left to right. Goes up to 97 then doesn't go any furthur.

Edit Edit: the furthur You are, the higher the number.

Edit Edit Edit: I made the number the width of the frame, But the opposit affect is happening, Closer you are, Quiter the sound.

Link to comment
Share on other sites

You know the Pythagoras theorem, right? The one that says:

pythagoras.gif

Well, basically, to calculate the distance between two points, you need to cast a line directly from a point to another and measure it.

The theorem can be applied to know the distance between two points in cartesian coordinates. Substituting the "c" term as the distance, "a" term with the difference between x coordinates and the "b" term with the the difference between y coordinates, the formula ends up being like this.

3e57a27a01bcb980027e92946c541760.png

This will give you the distance between the two points given.

The code, a bit more desglossated.

DifferenceX = Point1X - Point2X
DifferenceY = Point1Y - Point2Y
SquaredDistance = DifferenceX*DifferenceX + DifferenceY*DifferenceY
Distance = Sqrt(SquaredDistance)

Test.rar

  • Like 1
Link to comment
Share on other sites

You know the Pythagoras theorem, right? The one that says:

[qimg]http://www.mathsisfun.com/definitions/images/pythagoras.gif[/qimg]

Well, basically, to calculate the distance between two points, you need to cast a line directly from a point to another and measure it.

The theorem can be applied to know the distance between two points in cartesian coordinates. Substituting the "c" term as the distance, "a" term with the difference between x coordinates and the "b" term with the the difference between y coordinates, the formula ends up being like this.

[qimg]http://upload.wikimedia.org/math/3/e/5/3e57a27a01bcb980027e92946c541760.png[/qimg]

This will give you the distance between the two points given.

The code, a bit more desglossated.

DifferenceX = Point1X - Point2X
DifferenceY = Point1Y - Point2Y
SquaredDistance = DifferenceX*DifferenceX + DifferenceY*DifferenceY
Distance = Sqrt(SquaredDistance)

Thanks Damizean for the explanation and Example. +Rep

Link to comment
Share on other sites

I think Larks did something like that for me a while back.

The only thing I recall making you involving distance is that homing attack example, hahah.

OT: Anyway, I'm guessing you got your problem all fixed up already, but I suppose I'll just throw some things to keep in mind regardless.

I don't think MMF2 has this fixed yet, but if you try to set panning to a sample, it won't remain panned unless you continuously apply the panning to a channel ( sorta difficult to do to a specific sample if multiple instances of this sample are occurring simultaneously ). Also yes, I realize panning isn't related to volume, but honestly, I don't even think you can dynamically change a sample's volume unless it's modified via a channel too ( considering you have multiple instances of the same sound playing ) and I'm just making a prediction that if you wanted to make distance volume for a sound, that you may want to implement panning to give the sound a larger sense of position.

I was thinking of making a simple sound system that's handled via an array and constantly iterated to keep the different channel parameters updated, but I never had any interest expressed to me about it and I haven't got to the point of needing such a system for my own projects at the moment. *shrugs*

Link to comment
Share on other sites

The only thing I recall making you involving distance is that homing attack example, hahah.

OT: Anyway, I'm guessing you got your problem all fixed up already, but I suppose I'll just throw some things to keep in mind regardless.

I don't think MMF2 has this fixed yet, but if you try to set panning to a sample, it won't remain panned unless you continuously apply the panning to a channel ( sorta difficult to do to a specific sample if multiple instances of this sample are occurring simultaneously ). Also yes, I realize panning isn't related to volume, but honestly, I don't even think you can dynamically change a sample's volume unless it's modified via a channel too ( considering you have multiple instances of the same sound playing ) and I'm just making a prediction that if you wanted to make distance volume for a sound, that you may want to implement panning to give the sound a larger sense of position.

I was thinking of making a simple sound system that's handled via an array and constantly iterated to keep the different channel parameters updated, but I never had any interest expressed to me about it and I haven't got to the point of needing such a system for my own projects at the moment. *shrugs*

Yeah, Because you can hear the sound start to play, then the volume kicks in a tad delayed. Thats a problem, but I know it's possible. It's already been perfected!

Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...