Hi all! this is my first post here. Im spanish so forgive my english if it’s not clear.
Im doing a space game with little planets and gravity and stuff.
The problem I have now is with the thruster of the ship you control ingame. I attached an Elipsoid Particle Emitter to the ship object so it became its child, its emission point is moving with the ship and always in the same relative position.
What I want is the particles to act in a realistic way in the vacuum of space. If the particle speed is set to -100 and the ship is traveling at 300 the particle speed should be 200.
code on the ship:
var particleSpeed : float = -40;
var Thruster : GameObject;
function UpdateParticleVelocity(){
Thruster.particleEmitter.worldVelocity = rigidbody.velocity + Thruster.transform.up * particleSpeed;
}
function Update () {
UpdateParticleVelocity();
}
At the beginning I thought it was acting well but when I started to move faster and faster the emission point of the particles started to move and jump more and more forward in the ship velocity direction. Also it seems to have a big relation with the framerate.
Here are some screenshots:
This one is with zero velocity
http://img168.imageshack.us/img168/7503/rotating.png
Moving fast
http://img504.imageshack.us/img504/8127/fast.png
Moving fast and rotated
http://img694.imageshack.us/img694/9657/fastrotated.png
I dont know how to fix this so here I am asking for help.
Note: I tried to move the code from Update to FixedUpdate, both at the same time, to the Thruster too. All with the same result.
I found that the script is totally unnecessary since the options of the particle emitter allow to do the same thing setting “Emitter Velocity Scale” to 1 and using the “Local Velocity”. However the problem I mentioned above is still happening 
Hi, welcome to the forum!
Have you got Simulate in World Space enabled for the particle emitter? Without this enabled, the particles’ properties will be in the spacecraft’s local coordinates.
Thanks andeeee.
Yes, it is enabled. Was one of the first things I checked.
I tried setting no velocity so the only velocity the particles have is the velocity inherited from its parent… and it still happens. Also tried removing the particle collider but nothing changed.
Edit:
Physics seams to be ok but when rendered the objects that are moving vibrate on screen. Only the object the cam is focusing on appears stable.
Tomorrow I will try to attach and example showing it
ReEdit: The part of the objects vibrating is solved by setting in all objects to none interpolate. But in the case of the particles this option doesnt exist so the problem persist. Setting spacecraft’s rigidbody to extrapolate makes the best result with particles but not to other objects and still not perfect.
I found that the ParticleEmitter and the ParticleAnimator both set and change the particles several times per physics step. Also the particle emitter seems to extrapolate all particle parameters when emitting new particles. So I had to code my own emitter and animator in a FixedUpdate function loosing some funcionalities like color animation (what I can code myself too), but it works just as wanted and particles behave perfectly.
This is the script. Please if there’s something I could change for optimization or if you find something wrong, just tell me ^^
var emit : boolean;
var numParticles : int;
private var waitTime : float;
private var lastTime : float;
private var elapsedTime : float;
private var particles : Particle[];
private var deadParticle : int;
function Start(){
emit = false;
particles = new Particle[numParticles];
waitTime = particleEmitter.maxEnergy / numParticles;
lastEmissionTime = 0;
deadParticle = 0;
}
function FixedUpdate () {
elapsedTime = Time.time - lastTime;
for (var i : int= 0; i < numParticles; i++) {
particles[i].energy -= Time.deltaTime;
if(particles[i].energy <= 0)
deadParticle = i;
else
particles[i].position += particles[i].velocity * Time.deltaTime;
}
if(emit elapsedTime >= waitTime deadParticle >= 0){
particles[deadParticle].energy = particleEmitter.maxEnergy;
particles[deadParticle].size = particleEmitter.maxSize;
particles[deadParticle].color = Color.white;
particles[deadParticle].position =
transform.position +
transform.root.rigidbody.velocity * Time.deltaTime;
particles[deadParticle].velocity =
transform.root.rigidbody.velocity +
transform.TransformDirection(particleEmitter.localVelocity);
lastTime = Time.time;
deadParticle = -1;
}
particleEmitter.particles = particles;
}
I had to remove the ParticleAnimator because it can’t be disabled or I dont know how. Also the ParticleEmitter needs to be never emitting so I had to never change ParticleEmitter.emit or it would start emitting and messing with particle parameters.
At this moment the very big downside of doing this is that I lost the particle collisions and I dont know how to make a particle react to a collision instead of the body they hit. When a particle collides it sends a message to the objects attached to it and to the collider it hits but how do I know which particle collides?
There’s currently no way to find this out, unfortunately. At least not in the API - you may still be able to determine which particle hit from your own code somehow.