Death_Daniel Posted November 2, 2009 Report Share Posted November 2, 2009 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 More sharing options...
Asuma Posted November 2, 2009 Report Share Posted November 2, 2009 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. Link to comment Share on other sites More sharing options...
USC Posted November 2, 2009 Report Share Posted November 2, 2009 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 More sharing options...
Death_Daniel Posted November 2, 2009 Author Report Share Posted November 2, 2009 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. This doesn't seem to work USC :/. Link to comment Share on other sites More sharing options...
USC Posted November 2, 2009 Report Share Posted November 2, 2009 Opps, typed the wrong sign. Try making it LESS THAN 100. Link to comment Share on other sites More sharing options...
Death_Daniel Posted November 2, 2009 Author Report Share Posted November 2, 2009 Nope, doesn't work. Link to comment Share on other sites More sharing options...
Damizean Posted November 2, 2009 Report Share Posted November 2, 2009 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 More sharing options...
Death_Daniel Posted November 2, 2009 Author Report Share Posted November 2, 2009 Sorry um, I didn't understand what you just typed. What is Camera for? Link to comment Share on other sites More sharing options...
USC Posted November 2, 2009 Report Share Posted November 2, 2009 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 More sharing options...
Death_Daniel Posted November 2, 2009 Author Report Share Posted November 2, 2009 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 More sharing options...
USC Posted November 2, 2009 Report Share Posted November 2, 2009 Sqrt = Square Root, the math function. Link to comment Share on other sites More sharing options...
Death_Daniel Posted November 2, 2009 Author Report Share Posted November 2, 2009 I'm a little confused with Damizeans Method. Link to comment Share on other sites More sharing options...
Damizean Posted November 3, 2009 Report Share Posted November 3, 2009 You know the Pythagoras theorem, right? The one that says: 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. 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 1 Link to comment Share on other sites More sharing options...
Death_Daniel Posted November 3, 2009 Author Report Share Posted November 3, 2009 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 More sharing options...
LarkSS Posted November 4, 2009 Report Share Posted November 4, 2009 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 More sharing options...
Death_Daniel Posted November 4, 2009 Author Report Share Posted November 4, 2009 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 More sharing options...
Recommended Posts