Rocket Particles Showcase~

Hello again!
This time I am showing off my rocket particles! The side boosters are the same as provided, just recoloured (colour over time), while the main booster I borrowed elsewhere [link]

projectBoost_rocketParticlesShowcase

For anyone curious, I did run into some issues with getting things to work initially (trying to challenge myself), but this is some of the code I ended up with:

    private void HandleInputs()
    {
        if (disableControl) return;

        // Thrust
        if (Input.GetKey(KeyCode.Space))
        {
            rigidbody.AddRelativeForce(Vector3.up * mainThrustForce * Time.deltaTime, ForceMode.Force);
            playerAudio.PlayAudio(playerAudio.sfxRocketThrust);
            playerParticles.ToggleMainThrust();
        }
        else
        {
            playerAudio.PlayAudio(playerAudio.sfxRocketThrust, false);
            playerParticles.ToggleMainThrust(false);
        }

        // Tilt Left
        if (Input.GetKey(KeyCode.A))
        {
            HandleRotation(rotationAngle);
            playerParticles.ToggleSideThrust("R", true);
        }
        else
        {
            playerParticles.ToggleSideThrust("R", false);
        }

        // Tilt Right
        if (Input.GetKey(KeyCode.D))
        {
            HandleRotation(-rotationAngle);
            playerParticles.ToggleSideThrust("L", true);
        }
        else
        {
            playerParticles.ToggleSideThrust("L", false);
        }
    }
public class PlayerParticles : MonoBehaviour
{
    [SerializeField] public ParticleSystem crashExplosion = null;
    [SerializeField] public ParticleSystem winParticles = null;
    [SerializeField] private ParticleSystem leftThrustParticles = null;
    [SerializeField] private ParticleSystem rightThrustParticles = null;
    [SerializeField] private List<ParticleSystem> mainThrusterParticles = new List<ParticleSystem>();

    public void Play(ParticleSystem ptSys)
    {
        if (!ptSys.isPlaying)
            ptSys.Play();
    }
    public void Stop(ParticleSystem prtSys)
    {
        if (prtSys.isPlaying)
            prtSys.Stop();
    }

    public void ToggleMainThrust(bool toggleMain = true)
    {
        foreach (ParticleSystem part in mainThrusterParticles)
        {
            if (toggleMain)
                Play(part);

            else if (!toggleMain)
                Stop(part);
        }
    }

    public void ToggleSideThrust(string LR, bool enable)
    {
        ParticleSystem particleSystem = null;

        if (LR == "L") particleSystem = leftThrustParticles;
        else if (LR == "R") particleSystem = rightThrustParticles;

        if (enable)
                Play(particleSystem);
            else
                Stop(particleSystem);
    }
}

Good luck!

1 Like

Privacy & Terms