Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • 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 legopatch · Dec 19, 2012 at 07:49 PM · javascriptpositionparticlesystememit

How do I set the position of a newly emitted particle in a local enabled particleSystem?

Any help would be Greatly appreciated; I have been having this problem for over a week.

here is my current code attempt, made from what I could find in other unity answers and forums, problem is all of the particles apear at the same position, even when the position smoothly changes, all of the particles move as if attached to the hit point instead of leaving a trail behind.

 function EmitAtPos(position: Vector3, amount: int){
 particleSystem.Emit(amount);
 
 var particles: ParticleSystem.Particle[] = new 
 ParticleSystem.Particle[amount];
 
 if (particleSystem.GetParticles(particles) < amount) {
     Debug.Log("Hey!");
         return;
 }
 
 for (var i: int  = 0; i < amount; i++) {
         particles[i].position = position;
 } 
 particleSystem.SetParticles(particles, particleSystem.particleCount);
     Debug.Log(position);
 }
Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by CodeMasterMike · Dec 20, 2012 at 03:24 PM

You need to call the ParticleSystem.SetParticles-function as well, otherwise the changes will not be stored. Like so (in C# though, but the technique is the same):

 ParticleSystem m_currentParticleEffect = (ParticleSystem)GetComponent("ParticleSystem");
 ParticleSystem.Particle []ParticleList = new    ParticleSystem.Particle[m_currentParticleEffect.particleCount];
                m_currentParticleEffect.GetParticles(ParticleList);
 
                for(int i = 0; i < ParticleList.Length; ++i)
                {
                  ParticleList[i].position = newPosition;
                }     
 
                m_currentParticleEffect.SetParticles(ParticleList, m_currentParticleEffect.particleCount);

Link to SetParticles documentation.

Good luck!

Comment
Add comment · Show 4 · 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
avatar image legopatch · Dec 20, 2012 at 07:13 PM 0
Share

Ok, i added the setparticles part, and made sure all the code worked properly. However, when i ran the code, all of the particles got added to the same position(I double checked that the position was changing with a debug.log, so the particles are definitly not being added to multiple positions. I updated the original code to reflect the new changes. Is it possible that the setparticles function is overwriting the positions of the previous particles?

avatar image CodeMasterMike · Dec 20, 2012 at 10:30 PM 0
Share

I doubt that the SetParticle function would do something like that.

The issue what I can see, is that you have the position variable as a inparameter to the function. This means it will not change until next time you call the function. And therefor you set all particles to the same position.

And just so that you know, you are doing the Debug.Log(position); call at the very last in the function, meaning that the position only shown once, and it is not showing the individual position of the particles.

This code displays the position for each individual particle from the particle list:

      for (var i: int  = 0; i < amount; i++) 
      {
        particles[i].position = position;
        Debug.Log(particles[i].position);
     } 
avatar image legopatch · Dec 21, 2012 at 01:37 PM 0
Share

Ok, so this part is working as it should, but what I am trying to do is not compatable with this method. I have a laser that calls this once per frame that the laser hits something moving. The laser itself is also moving, so when the laser hits the object, it adds the particle system to a new object that becomes parented to the object that was hit. Then for every frame the laser hits the object, it adds particles by calling this function and passing in the hit point. I am baisically trying to get the laser to draw particles on the object. So..is there any way of doing this with the available tools?

avatar image CodeMasterMike · Dec 22, 2012 at 09:36 PM 0
Share

I don't have a answer to that question at the moment.

But you should put that question in a new separate thread, mostly because it is a new type of question, and you would get more answers that way.

And it would maybe help other people with the same question, since its easier to find when searching.

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.

Follow this Question

Answers Answers and Comments

10 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Dectect collision, but not actually stop the object? 1 Answer

Camera Scripting Help (Sims Style) 0 Answers

Instantiate cloned prefab to local position of an empty object 1 Answer

Collision with a particle system that invokes another particle system (javascript) 0 Answers

how do I tell when a object gets to a certain spot 1 Answer


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