[Tank Game Tutorial] Particles Only Appear While Turning

So I am following the tank game tutorial and have run into an issue with the particle system, happens on the included completed version too so it’s not something I did. The dust particles for the tank tracks only work when turning. The particles do not appear when going forward or backward. What could be the cause of this? I have no idea since I am so new.

I recreated the particle system and it caused the same issues. I am not sure what needs to be done or what could be the cause.

gif showing issue: https://i.gyazo.com/ed25fbdfd1d50da5300e1e01c07c6bf8.gif

Thanks for any help.

Added per the suggestion of @ThePersister. The particle system settings and the tank hierarchy.

I’m using Unity 5.5.0, and I wasn’t able to get the script @ThePersister wrote to work properly on its own for some reason, but I did successfully merge the code into TankMovement.cs, and it appears to be working. My solution doesn’t exactly seem ideal, since the particle system is relying on the keyboard input, not the actual speed of the tank (But it looks ok).

I changed Update() to the following:


private void Update()
    {
        // Store the player's input and make sure the audio for the engine is playing.
		m_MovementInputValue = Input.GetAxis (m_MovementAxisName);
		m_TurnInputValue = Input.GetAxis (m_TurnAxisName);
		EngineAudio ();
		if (Mathf.Abs (m_MovementInputValue) < 0.1f && Mathf.Abs (m_TurnInputValue) < 0.1f) {
			_updateParticleSystem( m_leftDustTrail, false );
			_updateParticleSystem( m_rightDustTrail, false );
		} else {
			_updateParticleSystem( m_leftDustTrail, true );
			_updateParticleSystem( m_rightDustTrail, true );
		}
    }

And I copied the _updateParticleSystem function without any changes:


    	private void _updateParticleSystem( ParticleSystem particleSystem, bool shouldBePlaying )
    	{
    		if ( particleSystem.isPlaying && !shouldBePlaying )
    		{
    			// Stop if currently playing and it shouldn't be.
    			particleSystem.Stop();
    		}
    		else if ( !particleSystem.isPlaying && shouldBePlaying )
    		{
    			// Play if currently not playing and it should be.
    			particleSystem.Play();
    		}
    	}
    }

Add new variables to the top of the class:


	public ParticleSystem m_leftDustTrail;
	public ParticleSystem m_rightDustTrail;

Do make sure that the settings for both particle systems are changed as mentioned:

“Right now you have Rate over Distance set to 10, set that to 0. And set Rate over Time to 10. Also, set Play on Awake to false. Do this for both dustTrail Particle Systems.”

Hope this helps.

Hi @jddg5wa,

Thank you for providing the extra information.
Since I can’t upgrade to 5.5 right now to provide specific help, I’ll give you an alternative solution.

This will work if the particleSystems are not stopped and played by other scripts.
Attach the following script to the tank object:

using UnityEngine;
using System.Collections;

public class TankParticlesExample : MonoBehaviour {

    public ParticleSystem m_leftDustTrail;
    public ParticleSystem m_rightDustTrail;
    private Rigidbody m_rigidBody;

    void Start ()
    {
        m_rigidBody = GetComponent<Rigidbody>();

        if (m_leftDustTrail == null)
        {
            Debug.LogError( "Don't forget to assign the LeftDustTrail in the inspector." );
        }

        if( m_rightDustTrail == null )
        {
            Debug.LogError( "Don't forget to assign the RightDustTrail in the inspector." );
        }
    }

    void Update()
    {
        // If velocity is greater than 0.5f, show particles, else, don't.
        if( m_rigidBody.velocity.magnitude > 0.5f)
        {
            _updateParticleSystem( m_leftDustTrail, true );
            _updateParticleSystem( m_rightDustTrail, true );
        }
        else
        {
            _updateParticleSystem( m_leftDustTrail, false );
            _updateParticleSystem( m_rightDustTrail, false );
        }
    }

    private void _updateParticleSystem( ParticleSystem particleSystem, bool shouldBePlaying )
    {
        if ( particleSystem.isPlaying && !shouldBePlaying )
        {
            // Stop if currently playing and it shouldn't be.
            particleSystem.Stop();
        }
        else if ( !particleSystem.isPlaying && shouldBePlaying )
        {
            // Play if currently not playing and it should be.
            particleSystem.Play();
        }
    }
}

Make sure to assign the ParticleSystems in the inspector, just drag and drop.
Right now you have Rate over Distance set to 10, set that to 0.
And set Rate over Time to 10.
Also, set Play on Awake to false.
Do this for both dustTrail Particle Systems.

That should make it all work nicely. You can adjust the value of 0.5f to your needs, a higher value would require a greater speed before showing dust trails.

If it doesn’t work, the Particle Systems are probably set to play and stop by other scripts.
In that case you can remove the particle systems (temporarily) to find out where that happens, because if you remove them and run the game, you should get an error. Double clicking on that error will lead you to its origin.

With that, you should be able to get it to work.
I hope this fulfills your request.

If this helped, please accept my answer, it’d be much appreciated!

If you need more details, let me know!

Best of luck!

Cheers,

ThePersister