+1 vote
by
retagged by

Hi, i'm trying to integrate FMOD to VPP, i've got a working  script for default Unity CarController, what do i need to modify to get RPM and Throttle from VPP? Thank you for helping and keep up that great project, it's awesome.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityStandardAssets.Vehicles.Car;

public class FMODEngineAudio : MonoBehaviour
{

    FMOD.Studio.EventInstance CarEngine;
    FMOD.Studio.ParameterInstance RPM;
    FMOD.Studio.ParameterInstance Throttle;

    CarController CC;

    void Awake()
    {
        CarEngine = FMODUnity.RuntimeManager.CreateInstance("event:/Car Engine");
        CarEngine.getParameter("RPM", out RPM);
        CarEngine.getParameter("Throttle", out Throttle);
        CC = GetComponent<CarController>();
    }

    void Start()
    {
        FMODUnity.RuntimeManager.AttachInstanceToGameObject(CarEngine, GetComponent<Transform>(), GetComponent<Rigidbody>());
        CarEngine.start();
    }

    void Update()
    {
        RPM.setValue(CC.Revs);
        Throttle.setValue(CC.AccelInput);
    }
}

1 Answer

0 votes
by
selected by
 
Best answer

It would be like this:

using UnityEngine;
using VehiclePhysics;

public class FMODEngineAudio : MonoBehaviour
{
    FMOD.Studio.EventInstance CarEngine;
    FMOD.Studio.ParameterInstance RPM;
    FMOD.Studio.ParameterInstance Throttle;

    VehicleBase vehicle;
    
    void Awake()
    {
        CarEngine = FMODUnity.RuntimeManager.CreateInstance("event:/Car Engine");
        CarEngine.getParameter("RPM", out RPM);
        CarEngine.getParameter("Throttle", out Throttle);
        vehicle = GetComponent<VehicleBase>();
    }

    void Start()
    {        
        FMODUnity.RuntimeManager.AttachInstanceToGameObject(CarEngine, GetComponent<Transform>(), GetComponent<Rigidbody>());
        CarEngine.start();
    }

    void Update()
    {
        float engineRpm = vehicle.data.Get(Channel.Vehicle, VehicleData.EngineRpm) / 1000.0f;
        float engineLoad = vehicle.data.Get(Channel.Vehicle, VehicleData.EngineLoad) / 1000.0f;
        
        RPM.setValue(engineRpm);
        Throttle.setValue(engineLoad);
    }
}

You may also retrieve many other values in the same way. Check out the Data Bus reference:

https://vehiclephysics.com/advanced/databus-reference/

Thanks for the code! I'll be integrating FMOD shortly as well, and this snippet is most useful.

by
Works like a charm!!! Realistic engine sounds for a realistic physics engine :) That's great. Keep up the good work, it's an awesome physics. I'm still struggling setting up a drivable car, but it's mostly my fault ( vehicle doesn't have enough grip with 150hp :\ )
by
Hi there, I'm doing something similar to this at the moment. I have years of experience in sound design but I'm a complete noob with game design and and trying to wrap my head around the unity/fmod side of things as I go. I have all my sounds for the different levels of RPM and throttle, but I'm a bit confused how to set up the throttle in FMOD. Obviously the RPM parameter just takes the car engine from >idle to max speed, on one layer in fmod. but then the different levels of throttle... do they go on seperate layers underneath? Any information, documents, tutorials you can send me way would be greatly appreciated, and I have a very strong feeling this code is going to help me when I eventually start to understand what Im doing haha. Thanks!
...