Voice input mechanics

Previously I ported over the function that allowed us to get the user their voice volume and several mechanics that made use of that volume. Now I adjusted the rotation mechanic and added support for a flame that gets bigger/smaller depending on voice volume.

Fire particles

I wanted to create a particle effect that looked like fire and manipulate the size of the fire with the user their voice.

My first step was to create a fire particle effect. I downloaded a pre-existing one (https://youtu.be/5Mw6NpSEb2o) and slightly modified some values.

The second step was manipulating several particleSystem values through a script. I wanted to modify the emissionRate so more/less particles were created. ParticleScale so the particles would be bigger with a louder voice and particleLifeTime so that the bigger particles would also be alive longer which would mean that they reached a higher altitude.

    private void Start()
    {
        ps = GetComponent<ParticleSystem>();
        psMain = ps.main;
        psEmission = ps.emission;
        baseLifeTime = psMain.startLifetime.constant / 16f;
        baseSize = particleScale / 16f;
    }

    // Update is called once per frame
    void Update()
    {
        ChangeParticleEmmision();
    }

    private void ChangeParticleEmmision()
    {
        float volume = GetVolume();
        if (debugMode)
            volume = debugVolumeValue;

        psEmission.rateOverTime = (int)Mathf.Round(volume) * particleEmmisionRate + baseEmmisionRate;
        psMain.startSize = baseSize + volume * particleScale;
        psMain.startLifetime = baseLifeTime + volume * particleLifeTime;
    }

Testing what the fire looked like was quite a hassle, because I had to put on my headset, make noises into my mic, then take off my headset and then modify some values. So to make that a bit easier for myself I implemented a debug value that I can modify in the inspector that simulates an input value.

    [Header("Debug Tools")]
    [SerializeField]
    private bool debugMode;
    [SerializeField]
    [Range(0f, 1f)]
    private float debugVolumeValue;

Fixing the rotation

We already had a voice input rotation, but it was implemented quite weird which caused the object with the script to reset their rotation to their original rotation after a short while. Which looked quite snappy and weird. So I quickly made a script for it that worked. Of course I just reused my debugging lines for this.

    void Update()
    {
        ChangeRotation();
    }

    private void ChangeRotation()
    {
        float volume = GetVolume();

        // ignore soft background noise so the rotation can be 0
        if (volume <= 0.15f)
            volume = 0f;

        if (debugMode)
            volume = debugVolumeValue;

        transform.Rotate(Vector3.up * (volume * rotationSpeed * Time.deltaTime));
    }

Last updated

Was this helpful?