Car Engine Sound Based On Motor Torque

Hi,

I’m creating a simple vehicle controller for a small game I’m working on, and I’m currently implementing the sound code for the engine when the car increases in speed. I have the following reference that I’ve studied and implemented with no problem ( see answer ) : -

However, I would like to have my car engine sound based on the actual Motor Torque, would appreciate any input on how I might amend my current code ( based on the help given above ) to achieve this ?

Thanks

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class vehicleSounds : MonoBehaviour {

    public float topSpeed = 100f;

    private float currentSpeed = 0;
    private float pitch = 0;
   
    void Update () {
        currentSpeed = transform.GetComponent<Rigidbody>().velocity.magnitude * 3.6f;

        pitch = currentSpeed / topSpeed;
        GetComponent<AudioSource>().pitch = pitch;

        //Debug.Log(currentSpeed); // Showcase current speed
    }
}

So, this is what I’m currently doing, would appreciate the help ?

Create an Animation Curve where x would be the torque and y would be the pitch.

Use the Evaluate function to get the pitch at the given torque and pass that over to your AudioSource.

Oh, wow, I think that might be a bit more advanced than what I was looking for, is there a simpler method ?

You could just use the current code you have, but replace current speed with the current motor torque and top speed with the maximum motor torque. I guess that would be a simpler way.

Also, engine sound is usually calculated from the engine RPM, not the torque. This post may help you out:

3 Likes