Search Unity

Unity Particle System Issue

Discussion in 'Scripting' started by PopRockLex, Apr 19, 2021.

  1. PopRockLex

    PopRockLex

    Joined:
    Sep 13, 2018
    Posts:
    17
    Any help is most appreciated, I'm not sure where I'm going wrong.
    I'm making a racing game and want there to be rocks that fly off the tires when you go offroad. The problem I'm having is with the particle system not firing when it should. I use this for the ground to trigger a bool and the bool fires fine.

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class GroundEffect : MonoBehaviour
    6. {
    7. public void OnTriggerEnter(Collider other)
    8. {
    9.     if (other.gameObject.CompareTag("Player"))
    10.     {
    11.         other.transform.root.GetComponentInChildren<KartController>().isOnGround = true;
    12.     }
    13. }
    14.  
    15. public void OnTriggerExit(Collider other)
    16. {
    17.     if (other.gameObject.CompareTag("Player"))
    18.     {
    19.         other.transform.root.GetComponentInChildren<KartController>().isOnGround = false;
    20.     }
    21. }
    22. }
    In this video, I show the plane settings and the error with my current rocks system and with a default particle system. It also only checks if "IsOnGround" is true which seems to work just fine. Here is the video -
    Here's the code I'm using in the video.

    Code (CSharp):
    1. void Update()
    2. {
    3.  
    4.     //Follow Collider
    5.     transform.position = sphere.transform.position - new Vector3(0, 0.4f, 0);
    6.  
    7.     if (!isOnBoostStrip)
    8.     {
    9.         //Accelerate
    10.         if (Input.GetButton("Fire1"))
    11.         {
    12.             speed = curAccel;
    13.         }
    14.  
    15.         //Reverse
    16.         if (Input.GetButton("Fire2"))
    17.         {
    18.             speed = -curAccel / 3;
    19.         }
    20.  
    21.         if (!isOnGround)
    22.         {
    23.             curAccel = zAcceleration;
    24.         }
    25.         if (isOnGround)
    26.         {
    27.             curAccel = zAcceleration / 2;
    28.         }
    29.     }
    30.     else if (isOnBoostStrip)
    31.     {
    32.         speed = zAcceleration * boostStripSpeed;
    33.         foreach (ParticleSystem p in exhaustParticles)
    34.         {
    35.             if (!isDrifting)
    36.             {
    37.                 c = turboColors[0];
    38.             }
    39.             var pmain = p.main;
    40.             pmain.startColor = c;
    41.             p.Play();
    42.         }
    43.     }
    44.  
    45.     //Rocks
    46.     if (isOnGround)
    47.     {
    48.         foreach (ParticleSystem p in groundParticles)
    49.         {
    50.             Debug.Log(isOnGround);
    51.             p.Play();
    52.         }
    53.     }
    54.  
    55. }
    My other particle systems all work great, I have them on the wheels and the exhaust and they work fine using the same "foreach". So I tried to play the exhaust particles instead of the ground ones in this instance, and they operate with the same weird behavior. Below someone suggested that I see if unity thinks the particles system is playing with a "Debug.Log(p.IsPlaying);" which I did. It shows that it's playing but it isn't.
    I don't get why the bump triggers it. My code just checks for "if (isOnGround)", now if I remove this the particle system will play non-stop but error-free.
     
  2. SpookyCat

    SpookyCat

    Joined:
    Jan 25, 2010
    Posts:
    3,768
    Try setting the Simulation space to world instead of local.
     
  3. PopRockLex

    PopRockLex

    Joined:
    Sep 13, 2018
    Posts:
    17
    My bad here's a screen shot of my particle system settings
    https://ibb.co/2KN5kN9