Problem to rotate a particle.

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…

https://vimeo.com/242646230

Here is the particle…

And here is the code:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class CandleFlame : MonoBehaviour
{
    private ParticleSystem flame;
    private float t;
    private float rotacion;
    private ParticleSystem.MainModule main;

    void Start()
    {
        flame = GetComponent<ParticleSystem>();
        main = flame.main;
    }

    void Update()
    {
        SetFlameRotation();
    }
    private void SetFlameRotation()
    {
        t += Time.deltaTime * 10f;
        rotacion = Mathf.PingPong(t, 50);
        main.startRotation = rotacion * Mathf.Deg2Rad;
    }
}

Any idea?

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.

2 Likes

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.

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.

1 Like

Sorry I meant to say as an alternative way to do the effect, not with a single particle. :wink:

Admittedly I haven’t watched the vid, but, is the Rotation over Lifetime Module an option?

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)

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.

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.

2 Likes