3
\$\begingroup\$

So I'm using Unity's simulate function to pre-render particles. It seems that simulate is not quite working as to what I expect. It's most likely a setting that I missed. But I just really cannot find the issue.

This is from inside the editor, I clicked on the particle object and just let it run This is from inside the editor, I clicked on the particle object and just let it run. This is what I'd like.

This is after I've run the game a little bit, then hit pause This is after I've run the game a little bit, then hit pause. This is what is currently happening, for some reason the particles get bigger.

Here is the script that I've attached.

public float initTime;
public ParticleEmitter partEmitter;
// Use this for initialization
void Start () {
    for (float i = 0.1f; i < initTime; i = i + 0.1f) {
        partEmitter.Simulate(i);
    }
}

I've run this scene in both Unity 3.5 and in Unity 4.0. Same thing happens in both versions.I'm pretty sure that it's something to do with the script. But I've tried many different pieces of code and they are all similar and do the same thing.

\$\endgroup\$
2
  • \$\begingroup\$ Have you changed your physics time step amount? I had a weird issue where the simulated particles would behave differently if I had the fixed time step set to anything other than the default (.02 I think). \$\endgroup\$
    – Tetrad
    Jan 16, 2013 at 18:30
  • \$\begingroup\$ @Tetrad Are you talking about my step in the for loop(incrementing of i)? I've just tested that. A smaller amount makes the particles bigger and vice-versa. If you speaking of the step setting in Time settings, I haven't changed anything there. \$\endgroup\$
    – Vincent P
    Jan 16, 2013 at 19:21

1 Answer 1

1
\$\begingroup\$

The function documentation states:

function Simulate (deltaTime : float) : void

That is, the function parameter is a time delta, a step in time. It is not a certain moment in time.

Physical simulations work based on discrete steps in time. And the stability of many simulations (or rather the error within a simulation) is directly related to the size of a time step you take.

In your code, you're taking increasingly large steps in time. While single particles might put up with that for a while, given a sufficiently large step they might start to become unstable.

Most likely your problem will be resolved by taking a number of fixed time steps of a relatively small size.

public float initTime;
public ParticleEmitter partEmitter;
// Use this for initialization
public float deltaTime = 0.1f;
void Start () {
    for (float i = 0.0f; i < initTime; i += deltaTime) {
        partEmitter.Simulate(deltaTime);
    }
}

I have taken your 0.1f here (a tenth of a second), but this might have to be even somewhat lower.

\$\endgroup\$
1
  • \$\begingroup\$ Your right in that you cant keep passing a bigger number to Simulate. \$\endgroup\$
    – Vincent P
    Mar 13, 2013 at 17:19

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .