Search Unity

Gaps in particle system when following player

Discussion in 'General Graphics' started by Deleted User, Oct 14, 2019.

  1. Deleted User

    Deleted User

    Guest

    I have a snow particle system in world space that follows the player, but when I move enough there is a gap in the particle system.



    Is there a way to keep it constant without setting it to local space cause I need the particles to move past the player.
     
    RationalCommander likes this.
  2. richardkettlewell

    richardkettlewell

    Unity Technologies

    Joined:
    Sep 9, 2015
    Posts:
    2,285
    What is generally desired for situations like this is a solution that teleports offscreen particles back onto the screen, so that the effect appears to be "infinite" but is really only simulating in a small area around the player.

    This can be achieved with some scripting, but there is nothing built-in to the Particle System to solve this.

    The general idea could be something like:
    * define a bounding box that is attached to the camera
    * on each frame, check each particle position. If the particle is outside the box, teleport it to the other side of the box (i.e. move from X to -X, (or -X to X) and Y to -Y or (-Y to Y) (probably no need to worry about vertical)

    There are 2 ways in Unity to do this:
    * The slow way, with ParticleSystem.GetParticles and ParticleSystem.SetParticles (e.g. https://docs.unity3d.com/ScriptReference/ParticleSystem.SetParticles.html)
    * The fast way, introduced in Unity 2019, using the C# Job System (e.g. https://docs.unity3d.com/2019.3/Doc...bs.IJobParticleSystemParallelFor.Execute.html)
     
  3. RationalCommander

    RationalCommander

    Joined:
    Aug 31, 2017
    Posts:
    1
    Hey richardkettlewell,
    I'm trying to achieve this for 2D rain and snow. I understand what you are suggesting, but have no idea how to actually go about it. I've checked the documentation, but it didn't help much. I should add, I'm not much of a coder :D.

    Would You happen have any examples of the code? I imagine it shouldn't be that difficult in 2D.

    Thank You in advance and Happy Holidays!