I started using FMOD and Mathf.Lerp to create a sound engine for my game in Unity.
I'm using the examples in documents/Fmod VEHICLE and using custom physics for my car. When I run the game the audio doesn't work, and problem with fmod studio event emitter and listener in gameobject.
Actually im using and following this https://www.fmod.com/docs/2.02/unity/integration-tutorial.html and I am new to FMOD and Unity, 50-50 you can say!
Can you please help me to run this and make it work with Max rpm and min and speed of car
This is the code I tried which has some issue:
using UnityEngine;
public class ArcadeEngineAudio : MonoBehaviour
{
PG.CarController rezx;
void Awake()
{
rezx = GetComponentInParent<PG.CarController>();
}
void Update()
{
float effectiveRPM = Mathf.Lerp(rezx.MinRPM, rezx.MaxRPM, rezx.CurrentSpeed);
var emitter = GetComponent<FMODUnity.StudioEventEmitter>();
emitter.SetParameter("RPM", effectiveRPM);
}
}
Thanks in advance.
I tried to use engine rpm, min rpm, and max rpm which doesn't work, even the current speed.
First off, save your CPU cycles and grab the emitter in the Awake function, storing it as a member.
var emitter = GetComponent<FMODUnity.StudioEventEmitter>()Now, to answer your original question, your
rezx.CurrentSpeedisn't a good input for theLerpfunction as that is looking for a value in a 0 - 1 range. If you're tying it to RPM then that suggests you will need to add a basic implementation for gears.A min and max speed will allow you to calculate that 0 - 1 range with
CurrentSpeed.With this class declared, you can add
public List<Gear> gears;to yourArcadeEngineAudioclass, allowing you to create new gears in the Inspector of the component.Once you have added your gears, you can use the
rezx.CurrentSpeedto track which gear you're currently in based on the speed.