Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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
2
Question by MichaelTodd · Jan 17, 2013 at 03:20 AM · particlesparticlesystemshuriken

Setting the position of particles in a (shuriken) ParticleSystem

Hi!

I'm trying to snap the particles of a particleSystem to a grid. Here is my code:

 public ParticleSystem particles;//I drag the particle system in question in to here.
 ParticleSystem.Particle[] gos = new ParticleSystem.Particle[300];

 // Use this for initialization
 void Start()
 {
     
 }

 // Update is called once per frame
 void Update()
 {
     int index = 0;
     int total = 0;
     Vector3 pos = Vector3.zero;

     total = particles.GetParticles(gos);
     
     while(index < total)
     {
         pos = gos[index].position;
         pos.x = Mathf.RoundToInt(pos.x);
         pos.y = Mathf.RoundToInt(pos.y);
         gos[index].position = pos;
         index++;
     }
 }
Comment
Add comment · Show 1
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 Loius · Jan 17, 2013 at 03:35 AM 0
Share

Good for you! pat

(there's not an actual question here, haha!)

3 Replies

· Add your reply
  • Sort: 
avatar image
2

Answer by MichaelTodd · Jan 17, 2013 at 06:42 AM

Yes! I am an idiot!

Thanks, that works!

 public ParticleSystem particles;
 ParticleSystem.Particle[] gos = new ParticleSystem.Particle[300];

 // Use this for initialization
 void Start()
 {
     
 }

 // Update is called once per frame
 void Update()
 {
     int index = 0;
     int total = 0;

     total = particles.GetParticles(gos);

    
     while(index < total)
     {
         xa.glx = gos[index].position;
         xa.glx.x = Mathf.RoundToInt(xa.glx.x);
         xa.glx.y = Mathf.RoundToInt(xa.glx.y);
         gos[index].position = xa.glx;
         index++;
     }

     particles.SetParticles(gos, total);
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
avatar image
0

Answer by Loius · Jan 17, 2013 at 03:36 AM

It looks like you haven't set the particles back. GetParticles returns a copy of the particle array, not the actual array.

As seen on the doc page, (http://docs.unity3d.com/Documentation/ScriptReference/30_search.html?q=getparticles), you need to use SetParticles after you're done changing the particle information.

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
avatar image
0

Answer by Ego65 · Oct 04, 2016 at 09:35 AM

although this is now 3 years old i say thanks !!!
thats exactly that what i needed ! to get positions of all particles.
I use the particle system itself to create a asteroid belt like a disk with a hole in the middle with the shape : mesh : Triangles method.
The disc is done in blender so its possible to deactivate the particle system after instantiating my asteroid prefab. The astprefab has its own script to have better control over collisions and destroying it by a healthscript. Because it seems the collision module in the particle system doesnt work accurately.

I changed your scripts to my needs like this :

 using UnityEngine;
 using System.Collections;
 
 [RequireComponent(typeof(ParticleSystem))]
 
 public class ParticlePosition : MonoBehaviour 
 {
     public GameObject thisObj;
     public GameObject thisAstprefab;
    
     public ParticleSystem particles;
     ParticleSystem.Particle[] gos = new ParticleSystem.Particle[1000];
 
     void Awake()
     {
         int index = 0;
         int total = 0;
         total = particles.GetParticles(gos);
         Vector3 pos = Vector3.zero;
 
         while(index < total)
         {
             pos = gos[index].position;
             pos.x = Mathf.RoundToInt(pos.x);
             pos.y = Mathf.RoundToInt(pos.y);
             gos[index].position = pos;
             Instantiate(thisAstprefab,gos[index].position,Quaternion.identity);
             index++;
         }
         if(index >= total)
         {
             thisObj.SetActive(false);
         }
         //particles.SetParticles(gos, total);
     }  
 }

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.

Follow this Question

Answers Answers and Comments

9 People are following this question.

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

Related Questions

Particle Burst on Button Press 1 Answer

What could cause OnParticleCollision to fail? 1 Answer

Spawn particles in grid pattern? 1 Answer

How to destroy live particle in Shuriken 1 Answer

(Shuriken) Accessing Particle[] Array Created in Inspector? 3 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