- Home /
Particles lag/stutter - choppy movement
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);
}
}
Brilliant!
Two and a half years later and I have done exactly as you described (building a third-person adventure game with custom player movement in FixedUpdate, requiring the camera to also use FixedUpdate) and I was experiencing Shuriken particle stutter (Unity 4.5.1f3).
Your script has immediately resolved the issue. I must say, I would have never thought of calling ps.Simulate() manually from within FixedUpdate. $$anonymous$$uch thanks!
Answer by KEric · Jul 27, 2017 at 08:59 AM
I think the problem was with the scale of the game world which was very small. When I've tested the gameplay with values of physics and rendering threads slowed down significantly (Time.timeScale, Time.fixedDeltaTime values) the choppy movement disappeared.
Answer by tayloreichhorst · Jun 11, 2015 at 09:58 PM
I know this is an old topic.. I was wondering, KEric, can you post the code you used to get your camera to follow smoothly so that the world isn't jerky around it? I am having that issue right now and I am pulling my hair out! I like my hair...
I have tried putting it into fixedupdate, but haven't had much luck, I wouldn't mind seeing if you're doing something that I'm missing.
Answer by pet1100 · Mar 16, 2017 at 08:34 PM
Remove simulation and use play/stop/clear instead. If possible add your particle system to an empty object and put it as a child of the camera (this will keep it at the same distance all the time). Particle system API you should take a loot at it. ;) https://docs.unity3d.com/ScriptReference/ParticleSystem.html
Your answer
![](https://koobas.hobune.stream/wayback/20220613140041im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Physics + first person camera = jitter? 4 Answers
Weird MoveTowards behaviour on low fps only. 0 Answers
Unity render lag questions 1 Answer
Particle System 2D dont works in Game 0 Answers