Search Unity

  1. We are migrating the Unity Forums to Unity Discussions. On July 12, the Unity Forums will become read-only.

    Please, do not make any changes to your username or email addresses at id.unity.com during this transition time.

    On July 15, Unity Discussions will become read-only until July 18, when the new design and the migrated forum contents will go live.


    Read our full announcement for more information and let us know if you have any questions.

Problem to rotate a particle.

Discussion in 'General Graphics' started by churi24, Jan 16, 2018.

  1. churi24

    churi24

    Joined:
    Sep 17, 2013
    Posts:
    98
    Hi, I'm trying to rotate a particle checking the move of the caracter. If the character goes to right, the particle should rotate to left, and viceversa. What I'm trying to do, is to simulate the motion of the flame on a candle.
    I made some tests to rotate and I found this problem, the rotation is not smooth. Maybe exist another way to solve this. The Material is Particles/Additive. I did a simple test, the other candle was made with a Texture Sheet Animation, but for testing purposes I did this the more simple I could.. to be practical I made a pingpong to show what is happening. I'm using Unity 2017.3.0f3

    Here is the video...


    Here is the particle..


    And here is the code:
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class CandleFlame : MonoBehaviour
    6. {
    7.     private ParticleSystem flame;
    8.     private float t;
    9.     private float rotacion;
    10.     private ParticleSystem.MainModule main;
    11.  
    12.     void Start()
    13.     {
    14.         flame = GetComponent<ParticleSystem>();
    15.         main = flame.main;
    16.     }
    17.  
    18.     void Update()
    19.     {
    20.         SetFlameRotation();
    21.     }
    22.     private void SetFlameRotation()
    23.     {
    24.         t += Time.deltaTime * 10f;
    25.         rotacion = Mathf.PingPong(t, 50);
    26.         main.startRotation = rotacion * Mathf.Deg2Rad;
    27.     }
    28. }
    Any idea?
     
  2. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,402
    You're modifying the start rotation. The start rotation is only used when a particle is initially spawned, and your particles have a lifetime of 2 seconds. That means roughly every two seconds when a new particle is spawned it'll use the value from the start rotation. The rest of the time it's ignored.

    If you're looking to rotate a live particle you can either modify the rotation using GetParticles() & SetParticles(), or you can change the particle rate and lifetime so that the particle doesn't last as long. The first option will give you much better control though is a little more expensive. Unfortunately the way Unity's current particle system works if you set the max particle count to 1, lifetime to 0.05, and set a rate of 1000 it still doesn't guarantee that there will be a particle visible every frame.
     
    CabinIcarus and churi24 like this.
  3. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,570
    You can also use the ExternalForces module and a wind zone to simulate the effect. Adjust the windzone with your script. Its particularly useful when you have multiple particles such as fire or smoke.
     
    Last edited: Jan 16, 2018
  4. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,402
    This case is a single quad with no actual motion, just rotation which external forces wouldn't be useful for. External forces would be great for handling something like a little smoke coming from the candle.
     
    karl_jones likes this.
  5. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,570
    Sorry I meant to say as an alternative way to do the effect, not with a single particle. ;)
     
  6. richardkettlewell

    richardkettlewell

    Unity Technologies

    Joined:
    Sep 9, 2015
    Posts:
    2,299
    Admittedly I haven’t watched the vid, but, is the Rotation over Lifetime Module an option?
     
  7. Torbach

    Torbach

    Joined:
    Jan 3, 2013
    Posts:
    10
    I'd use a stretched billboard
    0.005 speed aiming down to get the flame to aim Up
    rotate the parent system + local simulation

    (you will need to author the candle sprite sheet sideways for this to work)
     
  8. ifurkend

    ifurkend

    Joined:
    Sep 4, 2012
    Posts:
    350
    Unless you have serious concern of performance (in which case Particle System is usually falsely blamed), for a dynamic candle flame it is better to not to use a single texture but stack few glow particles emitted upward from the base, use color and size over lifetime modules to fade out the flame at the top end. Also change the simulation space to World.
     
  9. churi24

    churi24

    Joined:
    Sep 17, 2013
    Posts:
    98
    I'm using this because It's only one particle, one emission, and profiler doesn't show any impact on performance.
    Thank you people for the help! Now I have everything clear.
     
    karl_jones and richardkettlewell like this.