- Home /
Sound play with the speed of the rotation speed of an object.
ok.... I try to describe what I want to make.
I plan to create a special door sound system.... I want that the player is able to rotate a door via mouse imput (back and forward). the door can rotate ... let us say 120° degrees. that is the maximum. minimum is 0° degrees.
what I want to achieve is that there should be a squeaking sound BUT it should not play the sound fully when I grab the door and move it. it should play with the speed that the door rotates (audio pitch) + it should be perfectly fit with the door rotation degrees.
that means I would need normalized variables. like if the sound is at normal speed 3 seconds long. then the sound time (or position) normalized would be:
0.00 seconds = 0
1.50 seconds = 0.5
3.00 seconds = 1
and the door rotation degree normalized would be:
0° = 0
60° = 0.5
120° = 1
SOOOO.... Is it somehow possible to normalize the sound like I wrote above that it plays with the normalized speed?
I don't know how you would play the sound properly, but you can 'normalize' the time by dividing the doors rotation by whatever you limit it to. 120/120 = 1, 60/120 = 0.5, etc.
You can use AudioSource.time to set the current playback position although I don't know how mangled your audio will sound if you're playing it and scrubbing time constantly.
A better approach (in my opinion) is to simply have a looping sound who's pitch and volume is dependent on the doors angular velocity. I accomplished a really good sounding door swinging sound using this concept.
I tryed it now like you wrote here before I watched your comment and I have a little problem with the solution. I mean it works perfect with the door time like I wanted but when the door is pendeling very fast backwards and forwards it sounds very weird when the pitch gets fast to 0 and then back up. I tryed to lower with the speed ot the door the audio.volume but it sounds still weird. here is my script maybe you have any idea how to mitigate the weird sound...
#pragma strict
var doorDegreeLastFrame : float = 0.0;
var doorDegreeNow : float = 0.0;
var doorSpeed : float = 0.0;
function FixedUpdate()
{
doorDegreeNow = hingeJoint.angle;
doorSpeed = doorDegreeNow - doorDegreeLastFrame;
doorDegreeLastFrame = doorDegreeNow;
audio.pitch = doorSpeed;
audio.volume = $$anonymous$$athf.Abs($$anonymous$$athf.Clamp(doorSpeed,-1,1));
}
Yeah, you'll have to clamp the pitch to get it to sound right, it'll depend on your audio but I have $$anonymous$$e clamped between 0.85 & 1.
Answer by Harry64 · Dec 13, 2013 at 07:59 PM
but that would not work correctly here... see, I try to create the door sound as realistic as possible. so if I would clamp the audio pitch between 0.85 and 1 I would end up with only positive sounds that would always play.
in my script above the sound is able to play backwards. and the squeaky sound is always in the same position now. like you open a real door. the squeaks are always at the same positions. like at 30 degrees there starts the squeak and goes over to 70 degrees and another starts at 100 and goes over till 110 degrees.
but I think now I got an idea... maybe I can slow down the door so it wont be able to be opened and closed very very fast. then it would not sound so weird.... (tested.... its better but not ok...)
Weird, any time I try to use negative pitch it just goes silent, glad you got it figured out though! And yeah since pitch can go all the way up to 3 it will get really high pitched.
Your answer
Follow this Question
Related Questions
This door script causing door to go crazy? 2 Answers
Make door play sound when you open and close it ? 1 Answer
How would I reference the end of audio? 0 Answers
Door Opens When Not In Trigger And Sound Help 1 Answer
audio change object size 1 Answer