Hi,
i am currently struggeling with how to use an FMOD machinegun event in conjunction with my unity weapon script.
First here is my current setup:
I have an FMOD machinegun event setup closely resembling to the FMOD example events. So the event consists of a loop section for the actual shot, a tail section which is tied to a release parameter and an auto-stop parameter tied to an AHDSR modulator. So the event starts in the loop section and once the release parameter is set to 1 the event transitions to the tail section and then stops by means of the auto-stop parameter. This is all working as expected. I am also able to influence RPM by adjusting the length of the loop section.
In unity i have a shoot() method which is called in dependency of a (unity) RPM-parameter. The shoot() method triggers bullet spawn, particles effects and - as one would expect - also the start of the above FMOD event.
So obviously the general logic of RPM in the FMOD event and the RPM logic in unity is a different one:
The FMOD event is only started once on “trigger down” and then plays for as long as the trigger is being pressed. Only when the trigger is being released the event transitions to the tail section and is stopped after finishing that. FMOD RPM is solely driven by the loop length.
In unity the shoot() method is being called over and over again as long as the trigger is being pressed. RPM is driven by the frequency of calls to the shoot() method.
So in order to bring those two logics together i start to play the FMOD event once when the trigger is pressed down and the first shoot() method is called. On the subsequent calls to shot() (while trigger keeps being pressed) i leave the FMOD event alone and let it keep playing. On “triggerRelease” i stop the FMOD event.
As a result there is no “real” synch between gunshot sounds from FMOD and the number of calls to the shoot() method. This is somewhat not too tragic since when going “fullauto” the player can not really tell whether the number of heard gunshots matches the number of lets say recoil kicks from the gun. However this is only true for fullauto fire. The problem shows when the player triggers only a single gunshot (shoot()-method wise) but he will hear two gunshots from the FMOD event. This gets more and more obvious as the weapons RPM raises since for some reason it is still possible to click fast enough in order to only trigger one shoot() method but the FMOD event will already play the loop two times.
So since i am obviously not the first one trying to go down this route i would be really grateful for some insights on how this can be achieved.
On a sidenote: I also tried an alternative way by differentiating between the length of button presses. So on “buttondown” i started to count the time and after a certain amount of delay i started an FMOD full auto event. If the button wasn’t pressed down long enough (button was pressed only for an amount of time < delay and then released) i played an FMOD single shot event. However the delay was always noticable, you could tell that the sound started a little bit too late. So this didnt lead to any success.
So again, any best practices on this would be appreciated.
Cheers!