Search Unity

Change the direction of a particle system (Help please)

Discussion in 'Getting Started' started by Antropomorfo, Mar 4, 2016.

  1. Antropomorfo

    Antropomorfo

    Joined:
    Mar 4, 2016
    Posts:
    7
    I unable to change the direction of my particle system :(
    My particule system has only one particle (it simulate a shoot). The problem is that i want that this unique particle reach the hit point where a raycast (coming from the forward of the camera) is pointing every time it hit an object in the scene.
    But i cant change the F***ing direction of the particule. All post i read about this look like obsolete. (they are old)
    So i need your help...

    -I try to gain acces to the particle directly but particleSystem.particleEmitter is deprecated so i cant use particleSystem.particleEmitter.particles[0].transform.position+=direction* speed;
    -I try to use particleSystem.GetParticles but it return an integer
    -I try to rotate the particule system in the direction of the hit point by:
    direction = camHit.point - bullet.transform.position;
    direction.Normalize();
    bullet.transform.Rotate(direction);
    bullet.Emit(1);

    All those things dont work...and i dont find anything more in the Internet about how can i change the direction or the particle.

    Thank you so much !
     
  2. Antropomorfo

    Antropomorfo

    Joined:
    Mar 4, 2016
    Posts:
    7
    I post an image of my view scene
    upload_2016-3-4_20-56-57.png

    The particle starts at the cannon of the gun and has to end at the point where the crosshair is pointing.
    But i cant do that the particule change its direction
     

    Attached Files:

  3. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,859
    Don't try to use a particle system for a single particle. As you found, you won't have much control over the particle, because the particle system will be controlling it. You're making your life much harder than it should be.

    Just instantiate a prefab of your bullet, which has a simple script on it to move forward. And when you instantiate it, set its rotation equal to your gun. Job done!
     
  4. Antropomorfo

    Antropomorfo

    Joined:
    Mar 4, 2016
    Posts:
    7
    Yeah that is easier...and is a solution but image i have more particules....how can i change the direction?
    Imagine: my gun can shoot 10 consecutive particles every time i press Fire1 and i want that the 10 particules reach the hit point of my raycast.
    My problem is a basic problem...i need a solution for this. In the future if i work with particle systems i will need knwon to change the direction of particles.
     
  5. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,859
    Well, in theory you can just rotate the whole GameObject containing the particle system.
     
  6. Ryiah

    Ryiah

    Joined:
    Oct 11, 2012
    Posts:
    21,203
    Right, it returns an integer specifying the number of live particles in the system. You need to pass it an array to store those particles you want processed. Once you have modified them as necessary you simply pass the array into the SetParticles function along with that integer again. Check the first link for an example.

    http://docs.unity3d.com/ScriptReference/ParticleSystem.GetParticles.html
    http://docs.unity3d.com/ScriptReference/ParticleSystem.SetParticles.html

    Changing their direction simply involves modifying the velocity for each particle in the array.

    http://docs.unity3d.com/ScriptReference/Particle-velocity.html