Here’s the problem. In my game I have a moveable player which has a rigidbody attached. The position as well as it’s velocity is controlled in the script via simple assignment (rigidbody.position += etc). Now, the camera movement is based on player’s position as well as it’s velocity (it zoom out when the player goes faster and position itself respectively to it’s speed and position). Of course because the camera’s adjustments are based on the rigidbody I had the common problem of the world/cameras’s jerkiness. Based on what’s manual says and through pure logic I decided to put all the camera’s adjustment code into FixedUpdate function and that did the trick.
Finally, the matter from the question… having my camera and player moving exceptionally smoothly I’ve noticed that the particles from my particle systems (instantiated dynamically) had a choppy movement… Unfortunately, because my knowledge wasn’t sufficient I spent some time on it, trying to find something on the internet, but in vain. Then it struck me, as I’ve already had similar problem and a solution sufficed, I’ve moved particles simulation to FixedUpdate as well (code below), and voila, it started to work.
And of course the question: is it a good practice having my particles update functionality moved to FixedUpdate and if not, what’s the best solution for the situation described above?
using UnityEngine;
using System.Collections;
public class FixedTimeParticleSystem : MonoBehaviour {
private ParticleSystem ps;
private bool playing = false;
private void Awake() {
ps = GetComponent<ParticleSystem>();
}
public void Restart() {
ps.Simulate(0.0f, true, true);
playing = true;
}
public void Stop() {
playing = false;
}
void FixedUpdate() {
if(playing)
ps.Simulate(Time.fixedDeltaTime, true, false);
}
}