Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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.

share|improve this question
    
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). –  Tetrad Jan 16 '13 at 18:30
    
@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. –  Vincent P Jan 16 '13 at 19:21
add comment

2 Answers

up vote 1 down vote accepted

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.

share|improve this answer
    
Your right in that you cant keep passing a bigger number to Simulate. –  Vincent P Mar 13 '13 at 17:19
add comment

Well, the documentation for that function sais:

function Simulate (deltaTime : float) : void

Description

Advance particle simulation by given time.

This is useful for pre-warming particle emitters.

It should also be added that the deltaTime should be expressed in seconds (though that's not mentioned in the docs)

So I'm guessing that if you want to start your game and have the emitter emit particles as if it would have been started for (let's say) 10 seconds, all you have to do is call the function once with argument 10:

void Start () {
    partEmitter.Simulate(10);
}

I think that calling it from that loop (and thus, effectively calling it multiple times in a row) might not get you the desired result (i.e. looking similar to when you click on it and wait 10 seconds) because you're telling it to emit multiple times.

share|improve this answer
    
I'll give this a shot when I can. But almost every other example out there, runs it in a for loop. But yours does make more sense. –  Vincent P Jan 30 '13 at 4:59
    
Well, to be honest, it's something I haven't used a lot in Unity (scripting particle systems). It may be that you have to do something at the ParticleSystem object as well. I'll try it as well this evening and add another comment with the results. –  Shivan Dragon Jan 30 '13 at 9:16
    
Calling partEmitter.Simulate(10); made the problem worse, but it also just spawned a group of particles. Shot for your help though, learnt something. –  Vincent P Mar 13 '13 at 17:18
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.