- Home /
Move Particles
I cant figure out how to make my particles move with velocity.
tried a few things but none worked. and i dont understand the function get particles.
thank you for your time
using UnityEngine;
using System.Collections;
public class SunPhotons : MonoBehaviour {
public int InitSpeed=75;
int j=0;
public int NumberOfParticles=100;
private ParticleSystem.Particle[] Photons;
private ParticleSystem.Particle[] Photons2;
bool isInitializedPosition=false;
Vector3 LocationForDebug = new Vector3(0,0,0);
Vector3 SpeedForDebug = new Vector3 (10,10,10);
void Start () {
Photons = new ParticleSystem.Particle[NumberOfParticles];
}
// Update is called once per frame
void LateUpdate () {
int i;
ParticleSystem SunRay = GameObject.Find("SunRay").GetComponent<ParticleSystem>();
for ( i = 0; i < NumberOfParticles; i++)
{
if (!isInitializedPosition)
{
Photons[i].position=LocationForDebug;
Photons[i].color=new Color(10,0,0);
Photons[i].startLifetime=2;
Photons[i].lifetime=4;
Photons[i].size=0.2f;
}
Photons[i].velocity=SpeedForDebug;
Photons[i].angularVelocity=0.4f;
// Photons[i].position= new Vector3((i+j)/100f,0,0);
particleSystem.SetParticles(Photons,NumberOfParticles);
}
particleSystem.SetParticles(Photons,NumberOfParticles);
j++;
GameObject.Find("SunRay").GetComponent<ParticleSystem>().GetParticles(Photons2);
isInitializedPosition=true;
}
}
Answer by Berenger · Jun 05, 2012 at 03:20 PM
First, using Find(name) twice per frame to get the same gameobject is a bad idea. Do it once in Start.
Also, unless the system is emitting parcticles continuously, you don't need to get the particles each frame, only once. But you do need to Set them to commit the modifications. Not in the for loop, mind you.
Once this is fixed, you should see things more clearly.
Your answer
Follow this Question
Related Questions
Particle Force 0 Answers
Firing a particle effect prefab from your character 1 Answer
Particles shape scales issue after upgrading Unity to 4.2.2 0 Answers
how to rotate particles in a particle system 1 Answer
Change Particle Emitter fire rate? 2 Answers