• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by blackpag · Jun 18, 2012 at 07:11 AM · particlesblinking

blinking particles

Hi I created a code that with mouse movement i can change the velocity of particles but i have a problem, I cant understand why my particles sometime blink. the particles once a few second disappear for a second and then reappear . the particles continue with their path because of that i don't think they died.

I need ideas what could happen.

BP

EDIT: hmmm i thought i posted the code . here it is

 using UnityEngine;
 
 public class SunPhotonsExperiments : MonoBehaviour 
 {
     public Vector3 NorthPole = new Vector3(-10,5f,0);//The Location the photons should move
     public Vector3 Speed = new Vector3 (-4f,1f,0f);// The speed at which the photons start to move
     public float AccelDampen = 0.04f; //The value we multiply the speed change if it far away
     public float CloseToPoleDampen = 0.4f;////The value we multiply the speed change if it close
 
     ParticleSystem.Particle[] Photons2;//Our Particles
     int MAX_NUMBER_OF_PARTICLES = 500; //For the for loop and set.
 
     float StartTime;//for future uses
 
     float Mindistance = 0.2f;// The distance from which we consider the object arrived
     float MaxForce = 5;//Max allowed acceleration
     bool StartMovingToPole = false;//Should the particles start with the speed
     float MaxAllowedSpeed = 10f; // lowest speed which allowed for particles
 
     bool SpeedChanged = false;
 
     void Start() 
     {
         StartTime = Time.time;
         Photons2 = new ParticleSystem.Particle[MAX_NUMBER_OF_PARTICLES];
     }
 
 
     void FixedUpdate()
     {
         GameObject.Find("Sun").GetComponent<ParticleSystem>().GetParticles(Photons2);//Inits the array with current particles
         //ParticleSystem ps=   GameObject.Find("Sun").GetComponent<ParticleSystem>(); //For Debugging. Delete It
         int i;// for For loop
         if (GameObject.Find("Main Camera").GetComponent<MouseMovement>().IsMouseDraged) //
         {
             StartMovingToPole = true;//StartMoving To the Pole
             if(!SpeedChanged )
             { 
                 Speed = GameObject.Find("Main Camera").GetComponent<MouseMovement>().MouseDragSpeed*0.08f;
                 SpeedChanged = true;
             }
         }
         if (StartMovingToPole)
         {
             for ( i = 0; i < MAX_NUMBER_OF_PARTICLES; i++)
             {
                 Vector3 Force = NorthPole - Photons2[i].position;//also distance
                 if (Force.magnitude > 20)// if it is very far away (like at the beggining of the particle life)
                 {
                     Photons2[i].color = new Color(10,8,0);//yellow collor for fun.
                     Photons2[i].velocity = Speed;//make the photons velocity equal to the predetermined speed
 
                     if (i == MAX_NUMBER_OF_PARTICLES-1) //initialized
                         SpeedChanged = false;
 
                 }
                 else
                 {
                     float DampenValue;//dummy for storing the dampen value
                     if (Force.magnitude>10) //medium distance. low dampening
                         DampenValue = AccelDampen;
                     else 
                         DampenValue = CloseToPoleDampen;//close distance.high dampen
 
                     if (Force.magnitude < Mindistance) //if the photon close to the location
                     {
                         Photons2[i].velocity = new Vector3 (0f,0f,0f);//
                         Photons2[i].color = new Color(0,0,0,0) ;//make them invisible
                     }
                     if (Force.magnitude > MaxForce) //if the force(accel) is too high lower it to max predetermined value
                     {
                         Force.Normalize();
                         Force*=MaxForce;
                     }
                     this.Photons2[i].velocity = this.Photons2[i].velocity+DampenValue * Force;//calculate new velocity
                     if( this.Photons2[i].velocity.magnitude > MaxAllowedSpeed )
                         this.Photons2[i].velocity = this.Photons2[i].velocity.normalized * MaxAllowedSpeed;//if after all this the speed is too high. lower it
                 }
             }
             
             particleSystem.SetParticles(Photons2,MAX_NUMBER_OF_PARTICLES);    
         }
     }
 }
Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image bubblegumsoldier · Jun 18, 2012 at 12:08 PM 1
Share

Post your code!

avatar image Berenger · Jun 18, 2012 at 10:28 PM 0
Share

I'm sure he will.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Berenger · Jun 19, 2012 at 03:45 PM

I'm not really sure why they are blinking. Is it their speed that gets them suddenly out of view ? Do they get the color (0,0,0,0) when they shouldn't ?

Anyway, I can give you some optimization advices.

  • Don't call Find() that often. Do it once and store the value.

  • Vector3.magnitude isn't a value stored somewhere, it's a property that perform a calculation, you should store it at the beginning of the loop. Furthermore, for distance comparison, here is a quick math demonstration :

vec.magnitude < minDist;
vec.magnitude vec.magnitude < minDist minDist;
vec.sqrMangitude < minDist * minDist;

Store the sqrMag and compare it to 400 (20*20), 100 or minDistance * minDistance.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

How to produce the item collection particle effect? 1 Answer

[Shuriken] emitting particles at arbitrary locations 1 Answer

unable to disable game object after user input 1 Answer

Is it possible to adjust the properties of already generated particles? 1 Answer

Particles suddenly dissapear after bouncing on plane 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges