Search Unity

Particles follow iTween path

Discussion in 'Scripting' started by Alexx, Jun 4, 2011.

  1. Alexx

    Alexx

    Joined:
    Jun 4, 2011
    Posts:
    10
    Hi there,

    I'm relatively new to scripting, so the following task seems quite tough for me. I need to make particles follow the curves (well, path) in my 3D environment. I use particles for visualization of hot air (heating) and cool air (cooling) in the room containing several devices which produce of course cool and hot air. It seemed to me that the easiest way is to use iTween library, declare path(s) and run the script. However, I got issues when declaring the line on MoveTo function:

    Code (csharp):
    1. Particle[] particles = particleEmitter.particles;
    2. int i = 0;
    3.  
    4. while (i < particles.Length) {
    5.  
    6.  
    7. [B]iTween.MoveTo(particles[i],iTween.Hash("path",iTweenPath.GetPath(path), "time",20, "easetype",iTween.EaseType.easeInOutSine));[/B]
    8. i++;
    9.  }
    10. particleEmitter.particles = particles;
    It's because the first argument in MoveTo function should be GameObject type. Since I can not convert particles to the gameObject (or can I?), so I came on idea to create GameObject and then pass its coordinates to particles. Overall script looks like this:


    Code (csharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class FollowPath : MonoBehaviour {
    5.    
    6.     public string path;
    7.     GameObject temp;
    8.  
    9.     // Use this for initialization
    10.     void Start () {
    11.        
    12.         Particle[] particles = particleEmitter.particles;
    13.         int i = 0;
    14.         temp = new GameObject("Player");
    15.        
    16.         while (i < particles.Length) {
    17.  
    18.    
    19.         iTween.MoveTo(temp,iTween.Hash("path",iTweenPath.GetPath(path), "time",20, "easetype",iTween.EaseType.easeInOutSine));
    20.         particles[i].position = temp.transform.position;
    21.         i++;
    22.     }
    23.         particleEmitter.particles = particles;
    24.  
    25.        
    26.        
    27.     }
    28.    
    29.     // Update is called once per frame
    30.     void Update () {
    31.             Particle[] particles = particleEmitter.particles;
    32.         int i = 0;
    33.        
    34.         while (i < particles.Length) {
    35.  
    36.  
    37.         iTween.MoveTo(temp,iTween.Hash("path",iTweenPath.GetPath(path), "time",20, "easetype",iTween.EaseType.easeInOutSine));
    38.         particles[i].position = temp.transform.position;
    39.         i++;
    40.     }
    41.         particleEmitter.particles = particles;
    42.    
    43.     }
    44.    
    45.  
    46. }

    I managed to run my example, however, rendering goes quite slow (less than 1 FPS), seems that processor is quite busy and I can not see my particles. Am I scripting wrong or there is no way to do what I want? If not, I'm thinking to give up of particles and create polygons (arrow textures) that follow iTween path in a loop.

    Thanks in advance!