简体   繁体   中英

Unity 3D Particle System Snow effect

Within unity 3D, Im building a 2d runner within which I have created a particle system that emits snow like particles from a single location at the top right corner of the main camera off screen.

I attached the particle emitter to the main camera so theres always snow like particles on screen, however, as the speed of the main camera increases, so does the speed of the particle emitter, which eventually starts emitting particles off screen.

How can I change the settings of the emitter so that the speed of the emitter does not affect the direction of the particles. Lastly for more details, I have set the shape of the emitter to be a cone, and the simulation space to be world. Any help would be much appreciated

You can change the Simulation Space setting of your ParticleSystem component : Particle System main module .

EDIT Since I didn't noticed at first you wanted the particles speed to increase with the Camera accelerating (my bad...) here's a way you could fake the effect :

public class TestScript : MonoBehaviour
{
    #region Attributes
    [SerializeField]
    private float m_MaxTransformSpeed;

    [SerializeField]
    private float m_MinStartSpeed;
    [SerializeField]
    private float m_MaxStartSpeed;

    private ParticleSystem m_Particles;
    private Vector3 m_PreviousPosition;
    #endregion

    #region MonoBehaviour
    protected void Start()
    {
        m_Particles = GetComponent<ParticleSystem>();
    }

    protected void Update()
    {
        Vector3 cameraSpeed = transform.position - m_PreviousPosition;
        m_Particles.startSpeed = Mathf.Clamp(m_MinStartSpeed + (m_MaxStartSpeed - m_MinStartSpeed) * cameraSpeed.magnitude / m_MaxTransformSpeed, m_MinStartSpeed, m_MaxStartSpeed);
        m_PreviousPosition = transform.position;
    }
    #endregion
}

Instead of being based on only the latest frame you can either save N older positions and get the average speed value of N deltas or directly send the script the amount of movement you apply to your Camera if you move it manually.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM